Skip to content

Commit 5faceb9

Browse files
authored
Merge pull request #788 from man-ish-k/feat-additional-management-policy-combination
feat: support additional management policy combination
2 parents 10d8643 + 780e99f commit 5faceb9

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

pkg/reconciler/managed/policies.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ func defaultSupportedManagementPolicies() []sets.Set[xpv1.ManagementAction] {
8989
// Useful when the same external resource is managed by multiple
9090
// managed resources.
9191
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionUpdate),
92+
// Import mode: Allows observation of existing resources and populates spec.forProvider
93+
// through late initialization, without making any changes to the external resource.
94+
// Useful for safely importing existing resources to discover their current state.
95+
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionLateInitialize),
96+
// No Create, no Delete. Just Observe, Update and LateInitialize.
97+
// Useful when external resource lifecycle is managed elsewhere but you want
98+
// to allow Crossplane to make updates and discover state changes.
99+
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize),
92100
}
93101
}
94102

pkg/reconciler/managed/reconciler_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,60 @@ func TestReconciler(t *testing.T) {
19171917
},
19181918
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
19191919
},
1920+
"ObserveAndLateInitializePolicy": {
1921+
reason: "If management policy is set to Observe and LateInitialize, reconciliation should proceed",
1922+
args: args{
1923+
m: &fake.Manager{
1924+
Client: &test.MockClient{
1925+
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
1926+
mg := obj.(*fake.Managed)
1927+
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionLateInitialize})
1928+
return nil
1929+
}),
1930+
MockUpdate: test.NewMockUpdateFn(nil),
1931+
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, _ client.Object, _ ...client.SubResourceUpdateOption) error {
1932+
return nil
1933+
}),
1934+
},
1935+
Scheme: fake.SchemeWith(&fake.Managed{}),
1936+
},
1937+
mg: resource.ManagedKind(fake.GVK(&fake.Managed{})),
1938+
o: []ReconcilerOption{
1939+
WithManagementPolicies(),
1940+
WithReconcilerSupportedManagementPolicies(defaultSupportedManagementPolicies()),
1941+
},
1942+
},
1943+
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
1944+
},
1945+
"ObserveUpdateAndLateInitializePolicy": {
1946+
reason: "If management policy is set to Observe, Update and LateInitialize, reconciliation should proceed",
1947+
args: args{
1948+
m: &fake.Manager{
1949+
Client: &test.MockClient{
1950+
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
1951+
mg := obj.(*fake.Managed)
1952+
mg.SetManagementPolicies(xpv1.ManagementPolicies{
1953+
xpv1.ManagementActionObserve,
1954+
xpv1.ManagementActionUpdate,
1955+
xpv1.ManagementActionLateInitialize,
1956+
})
1957+
return nil
1958+
}),
1959+
MockUpdate: test.NewMockUpdateFn(nil),
1960+
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, _ client.Object, _ ...client.SubResourceUpdateOption) error {
1961+
return nil
1962+
}),
1963+
},
1964+
Scheme: fake.SchemeWith(&fake.Managed{}),
1965+
},
1966+
mg: resource.ManagedKind(fake.GVK(&fake.Managed{})),
1967+
o: []ReconcilerOption{
1968+
WithManagementPolicies(),
1969+
WithReconcilerSupportedManagementPolicies(defaultSupportedManagementPolicies()),
1970+
},
1971+
},
1972+
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
1973+
},
19201974
}
19211975

19221976
for name, tc := range cases {

0 commit comments

Comments
 (0)