@@ -1952,93 +1952,6 @@ func TestReconciler(t *testing.T) {
19521952 },
19531953 want : want {result : reconcile.Result {Requeue : true }},
19541954 },
1955- "ManagementPolicyMustCreateCreateSuccessful" : {
1956- reason : "Successful managed resource creation using management policy MustCreate should trigger a requeue after a short wait." ,
1957- args : args {
1958- m : & fake.Manager {
1959- Client : & test.MockClient {
1960- MockGet : test .NewMockGetFn (nil , func (obj client.Object ) error {
1961- mg := asLegacyManaged (obj , 42 )
1962- mg .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionMustCreate , xpv1 .ManagementActionDelete })
1963- return nil
1964- }),
1965- MockUpdate : test .NewMockUpdateFn (nil ),
1966- MockStatusUpdate : test .MockSubResourceUpdateFn (func (_ context.Context , obj client.Object , _ ... client.SubResourceUpdateOption ) error {
1967- want := newLegacyManaged (42 )
1968- want .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionMustCreate , xpv1 .ManagementActionDelete })
1969- meta .SetExternalCreatePending (want , time .Now ())
1970- meta .SetExternalCreateSucceeded (want , time .Now ())
1971- want .SetConditions (xpv1 .ReconcileSuccess ().WithObservedGeneration (42 ))
1972- want .SetConditions (xpv1 .Creating ().WithObservedGeneration (42 ))
1973- if diff := cmp .Diff (want , obj , test .EquateConditions (), cmpopts .EquateApproxTime (1 * time .Second )); diff != "" {
1974- reason := "Successful managed resource creation should be reported as a conditioned status."
1975- t .Errorf ("\n Reason: %s\n -want, +got:\n %s" , reason , diff )
1976- }
1977- return nil
1978- }),
1979- },
1980- Scheme : fake .SchemeWith (& fake.LegacyManaged {}),
1981- },
1982- mg : resource .ManagedKind (fake .GVK (& fake.LegacyManaged {})),
1983- o : []ReconcilerOption {
1984- WithInitializers (),
1985- WithManagementPolicies (),
1986- WithReferenceResolver (ReferenceResolverFn (func (_ context.Context , _ resource.Managed ) error { return nil })),
1987- WithExternalConnector (& NopConnector {}),
1988- WithCriticalAnnotationUpdater (CriticalAnnotationUpdateFn (func (_ context.Context , _ client.Object ) error { return nil })),
1989- WithFinalizer (resource.FinalizerFns {AddFinalizerFn : func (_ context.Context , _ resource.Object ) error { return nil }}),
1990- },
1991- },
1992- want : want {result : reconcile.Result {Requeue : true }},
1993- },
1994- "ResourceExistsMustCreateError" : {
1995- reason : "When a resource exists and the policy is MustCreate an error condition should be raised." ,
1996- args : args {
1997- m : & fake.Manager {
1998- Client : & test.MockClient {
1999- MockGet : test .NewMockGetFn (nil , func (obj client.Object ) error {
2000- mg := asLegacyManaged (obj , 42 )
2001- mg .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionMustCreate , xpv1 .ManagementActionDelete })
2002- return nil
2003- }),
2004- MockStatusUpdate : test .MockSubResourceUpdateFn (func (_ context.Context , obj client.Object , _ ... client.SubResourceUpdateOption ) error {
2005- want := newLegacyManaged (42 )
2006- want .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionMustCreate , xpv1 .ManagementActionDelete })
2007- want .SetConditions (xpv1 .Creating ().WithObservedGeneration (42 ), xpv1 .ReconcileError (errors .New (errMustCreate )).WithObservedGeneration (42 ).WithObservedGeneration (42 ))
2008- if diff := cmp .Diff (want , obj , test .EquateConditions ()); diff != "" {
2009- reason := "With MustCreate, a successful managed resource observation with no creation annotations should be reported as an error condition."
2010- t .Errorf ("\n Reason: %s\n -want, +got:\n %s" , reason , diff )
2011- }
2012- return nil
2013- }),
2014- },
2015- Scheme : fake .SchemeWith (& fake.LegacyManaged {}),
2016- },
2017- mg : resource .ManagedKind (fake .GVK (& fake.LegacyManaged {})),
2018- o : []ReconcilerOption {
2019- WithInitializers (),
2020- WithManagementPolicies (),
2021- WithExternalConnector (ExternalConnectorFn (func (_ context.Context , _ resource.Managed ) (ExternalClient , error ) {
2022- c := & ExternalClientFns {
2023- ObserveFn : func (_ context.Context , _ resource.Managed ) (ExternalObservation , error ) {
2024- return ExternalObservation {ResourceExists : true }, nil
2025- },
2026- DisconnectFn : func (_ context.Context ) error {
2027- return nil
2028- },
2029- }
2030- return c , nil
2031- })),
2032- withLocalConnectionPublishers (LocalConnectionPublisherFns {
2033- PublishConnectionFn : func (_ context.Context , _ resource.LocalConnectionSecretOwner , _ ConnectionDetails ) (bool , error ) {
2034- return false , nil
2035- },
2036- }),
2037- WithFinalizer (resource.FinalizerFns {AddFinalizerFn : func (_ context.Context , _ resource.Object ) error { return nil }}),
2038- },
2039- },
2040- want : want {result : reconcile.Result {Requeue : false }},
2041- },
20421955 "ManagementPolicyImmutableNoDiff" : {
20431956 reason : "Successful reconciliation skipping update should trigger a requeue after a long wait." ,
20441957 args : args {
@@ -2098,15 +2011,15 @@ func TestReconciler(t *testing.T) {
20982011 Client : & test.MockClient {
20992012 MockGet : test .NewMockGetFn (nil , func (obj client.Object ) error {
21002013 mg := asLegacyManaged (obj , 42 )
2101- mg .SetManagementPolicies (xpv1 .ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionLateInitialize , xpv1 .ManagementActionCreate , xpv1 .ManagementActionDelete })
2014+ mg .SetManagementPolicies (xpv2 .ManagementPolicies {xpv2 .ManagementActionObserve , xpv2 .ManagementActionLateInitialize , xpv2 .ManagementActionCreate , xpv2 .ManagementActionDelete })
21022015
21032016 return nil
21042017 }),
21052018 MockUpdate : test .NewMockUpdateFn (errBoom ),
21062019 MockStatusUpdate : test .MockSubResourceUpdateFn (func (_ context.Context , obj client.Object , _ ... client.SubResourceUpdateOption ) error {
21072020 want := newLegacyManaged (42 )
2108- want .SetManagementPolicies (xpv1 .ManagementPolicies {xpv1 .ManagementActionObserve , xpv1 .ManagementActionLateInitialize , xpv1 .ManagementActionCreate , xpv1 .ManagementActionDelete })
2109- want .SetConditions (xpv1 .ReconcileForbidden ().WithObservedGeneration (42 ).WithMessage ("External resource differs from desired state, but will not update due to missing 'Update' managementPolicy. Diff:\n mock diff" ))
2021+ want .SetManagementPolicies (xpv2 .ManagementPolicies {xpv2 .ManagementActionObserve , xpv2 .ManagementActionLateInitialize , xpv2 .ManagementActionCreate , xpv2 .ManagementActionDelete })
2022+ want .SetConditions (xpv2 .ReconcileForbidden ().WithObservedGeneration (42 ).WithMessage ("External resource differs from desired state, but will not update due to missing 'Update' managementPolicy. Diff:\n mock diff" ))
21102023
21112024 if diff := cmp .Diff (want , obj , test .EquateConditions ()); diff != "" {
21122025 reason := `Managed resource should acquire Synced=False/ReconcileForbidden status condition when update is not allowed and a diff exists.`
@@ -2194,53 +2107,6 @@ func TestReconciler(t *testing.T) {
21942107 },
21952108 want : want {result : reconcile.Result {RequeueAfter : defaultPollInterval }},
21962109 },
2197- "ManagementPolicyOrphanUpdateSuccessful" : {
2198- reason : "A successful managed resource update using management policies should trigger a requeue after a long wait." ,
2199- args : args {
2200- m : & fake.Manager {
2201- Client : & test.MockClient {
2202- MockGet : test .NewMockGetFn (nil , func (obj client.Object ) error {
2203- mg := asLegacyManaged (obj , 42 )
2204- mg .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionOrphan })
2205- return nil
2206- }),
2207- MockStatusUpdate : test .MockSubResourceUpdateFn (func (_ context.Context , obj client.Object , _ ... client.SubResourceUpdateOption ) error {
2208- want := newLegacyManaged (42 )
2209- want .SetManagementPolicies (xpv1.ManagementPolicies {xpv1 .ManagementActionOrphan })
2210- want .SetConditions (xpv1 .ReconcileSuccess ().WithObservedGeneration (42 ))
2211- if diff := cmp .Diff (want , obj , test .EquateConditions ()); diff != "" {
2212- reason := "A successful managed resource update should be reported as a conditioned status."
2213- t .Errorf ("\n Reason: %s\n -want, +got:\n %s" , reason , diff )
2214- }
2215- return nil
2216- }),
2217- },
2218- Scheme : fake .SchemeWith (& fake.LegacyManaged {}),
2219- },
2220- mg : resource .ManagedKind (fake .GVK (& fake.LegacyManaged {})),
2221- o : []ReconcilerOption {
2222- WithInitializers (),
2223- WithManagementPolicies (),
2224- WithReferenceResolver (ReferenceResolverFn (func (_ context.Context , _ resource.Managed ) error { return nil })),
2225- WithExternalConnector (ExternalConnectorFn (func (_ context.Context , _ resource.Managed ) (ExternalClient , error ) {
2226- c := & ExternalClientFns {
2227- ObserveFn : func (_ context.Context , _ resource.Managed ) (ExternalObservation , error ) {
2228- return ExternalObservation {ResourceExists : true , ResourceUpToDate : false }, nil
2229- },
2230- UpdateFn : func (_ context.Context , _ resource.Managed ) (ExternalUpdate , error ) {
2231- return ExternalUpdate {}, nil
2232- },
2233- DisconnectFn : func (_ context.Context ) error {
2234- return nil
2235- },
2236- }
2237- return c , nil
2238- })),
2239- WithFinalizer (resource.FinalizerFns {AddFinalizerFn : func (_ context.Context , _ resource.Object ) error { return nil }}),
2240- },
2241- },
2242- want : want {result : reconcile.Result {RequeueAfter : defaultPollInterval }},
2243- },
22442110 "ManagementPolicyUpdateUpdateSuccessful" : {
22452111 reason : "A successful managed resource update using management policies should trigger a requeue after a long wait." ,
22462112 args : args {
0 commit comments