Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support additional management policy combination #788

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/reconciler/managed/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func defaultSupportedManagementPolicies() []sets.Set[xpv1.ManagementAction] {
// Useful when the same external resource is managed by multiple
// managed resources.
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionUpdate),
// Import mode: Allows observation of existing resources and populates spec.forProvider
// through late initialization, without making any changes to the external resource.
// Useful for safely importing existing resources to discover their current state.
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionLateInitialize),
// No Create, no Delete. Just Observe, Update and LateInitialize.
// Useful when external resource lifecycle is managed elsewhere but you want
// to allow Crossplane to make updates and discover state changes.
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize),
}
}

Expand Down
54 changes: 54 additions & 0 deletions pkg/reconciler/managed/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,60 @@ func TestReconciler(t *testing.T) {
},
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
},
"ObserveAndLateInitializePolicy": {
reason: "If management policy is set to Observe and LateInitialize, reconciliation should proceed",
args: args{
m: &fake.Manager{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
mg := obj.(*fake.Managed)
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionLateInitialize})
return nil
}),
MockUpdate: test.NewMockUpdateFn(nil),
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, _ client.Object, _ ...client.SubResourceUpdateOption) error {
return nil
}),
},
Scheme: fake.SchemeWith(&fake.Managed{}),
},
mg: resource.ManagedKind(fake.GVK(&fake.Managed{})),
o: []ReconcilerOption{
WithManagementPolicies(),
WithReconcilerSupportedManagementPolicies(defaultSupportedManagementPolicies()),
},
},
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
},
"ObserveUpdateAndLateInitializePolicy": {
reason: "If management policy is set to Observe, Update and LateInitialize, reconciliation should proceed",
args: args{
m: &fake.Manager{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
mg := obj.(*fake.Managed)
mg.SetManagementPolicies(xpv1.ManagementPolicies{
xpv1.ManagementActionObserve,
xpv1.ManagementActionUpdate,
xpv1.ManagementActionLateInitialize,
})
return nil
}),
MockUpdate: test.NewMockUpdateFn(nil),
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, _ client.Object, _ ...client.SubResourceUpdateOption) error {
return nil
}),
},
Scheme: fake.SchemeWith(&fake.Managed{}),
},
mg: resource.ManagedKind(fake.GVK(&fake.Managed{})),
o: []ReconcilerOption{
WithManagementPolicies(),
WithReconcilerSupportedManagementPolicies(defaultSupportedManagementPolicies()),
},
},
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
},
}

for name, tc := range cases {
Expand Down