Skip to content

Commit 8e1ca4b

Browse files
committed
Revert "Merge pull request #864 from nokia/add_orphan_policy"
This reverts commit 26bc05a, reversing changes made to af8c3fb. Signed-off-by: lsviben <sviben.lovro@gmail.com>
1 parent 5a8380a commit 8e1ca4b

File tree

5 files changed

+5
-274
lines changed

5 files changed

+5
-274
lines changed

apis/common/policies.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ManagementPolicies []ManagementAction
2222

2323
// A ManagementAction represents an action that the Crossplane controllers
2424
// can take on an external resource.
25-
// +kubebuilder:validation:Enum=Observe;Create;Update;Delete;LateInitialize;*;MustCreate;Orphan
25+
// +kubebuilder:validation:Enum=Observe;Create;Update;Delete;LateInitialize;*;MustCreate
2626
type ManagementAction string
2727

2828
const (
@@ -53,10 +53,6 @@ const (
5353
// ManagementActionMustCreate means that the external resource MUST be created
5454
// by the managed resource and if it already exists an error condition is raised.
5555
ManagementActionMustCreate ManagementAction = "MustCreate"
56-
57-
// ManagementActionOrphan means that all actions except Delete will be taken
58-
// by the Crossplane controllers.
59-
ManagementActionOrphan ManagementAction = "Orphan"
6056
)
6157

6258
// A DeletionPolicy determines what should happen to the underlying external

apis/common/v1/policies.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ const (
5656
// ManagementActionMustCreate means that the external resource must be created
5757
// by this MR and if it already exists an error condition is raised and no further processing is executed.
5858
ManagementActionMustCreate = common.ManagementActionMustCreate
59-
60-
// ManagementActionOrphan means that all actions except Delete will be taken
61-
// by the Crossplane controllers.
62-
ManagementActionOrphan ManagementAction = common.ManagementActionOrphan
6359
)
6460

6561
// A DeletionPolicy determines what should happen to the underlying external

pkg/reconciler/managed/policies.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ func defaultSupportedManagementPolicies() []sets.Set[xpv1.ManagementAction] {
135135
// Useful when external resource lifecycle is managed elsewhere but you want
136136
// to allow Crossplane to make updates and discover state changes.
137137
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize),
138-
// Orphan allows all actions except Delete.
139-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionOrphan),
140138
}
141139
}
142140

@@ -219,7 +217,7 @@ func (m *ManagementPoliciesResolver) ShouldCreate() bool {
219217
return true
220218
}
221219

222-
return m.managementPolicies.HasAny(xpv1.ManagementActionCreate, xpv1.ManagementActionAll, xpv1.ManagementActionMustCreate, xpv1.ManagementActionOrphan)
220+
return m.managementPolicies.HasAny(xpv1.ManagementActionCreate, xpv1.ManagementActionAll, xpv1.ManagementActionMustCreate)
223221
}
224222

225223
// MustCreate returns true if the Create action is required. If the resource already exists an error will
@@ -240,7 +238,7 @@ func (m *ManagementPoliciesResolver) ShouldUpdate() bool {
240238
return true
241239
}
242240

243-
return m.managementPolicies.HasAny(xpv1.ManagementActionUpdate, xpv1.ManagementActionAll, xpv1.ManagementActionOrphan)
241+
return m.managementPolicies.HasAny(xpv1.ManagementActionUpdate, xpv1.ManagementActionAll)
244242
}
245243

246244
// ShouldLateInitialize returns true if the LateInitialize action is allowed.
@@ -250,7 +248,7 @@ func (m *ManagementPoliciesResolver) ShouldLateInitialize() bool {
250248
return true
251249
}
252250

253-
return m.managementPolicies.HasAny(xpv1.ManagementActionLateInitialize, xpv1.ManagementActionAll, xpv1.ManagementActionOrphan)
251+
return m.managementPolicies.HasAny(xpv1.ManagementActionLateInitialize, xpv1.ManagementActionAll)
254252
}
255253

256254
// ShouldOnlyObserve returns true if the Observe action is allowed and all

pkg/reconciler/managed/reconciler_legacy_test.go

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestReconciler(t *testing.T) {
8686
},
8787
want: want{result: reconcile.Result{}},
8888
},
89-
"UnpublishConnectionDetailsDeletionPolicyDeleteOrphan": {
89+
"UnpublishConnectionDetailsDeletionPolicyDeleteOrpahn": {
9090
reason: "Errors unpublishing connection details should trigger a requeue after a short wait.",
9191
args: args{
9292
m: &fake.Manager{
@@ -1858,45 +1858,6 @@ func TestReconciler(t *testing.T) {
18581858
},
18591859
want: want{result: reconcile.Result{Requeue: true}},
18601860
},
1861-
"ManagementPolicyOrphanCreateSuccessful": {
1862-
reason: "Successful managed resource creation using management policy Orphan should trigger a requeue after a short wait.",
1863-
args: args{
1864-
m: &fake.Manager{
1865-
Client: &test.MockClient{
1866-
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
1867-
mg := asLegacyManaged(obj, 42)
1868-
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionOrphan})
1869-
return nil
1870-
}),
1871-
MockUpdate: test.NewMockUpdateFn(nil),
1872-
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, obj client.Object, _ ...client.SubResourceUpdateOption) error {
1873-
want := newLegacyManaged(42)
1874-
want.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionOrphan})
1875-
meta.SetExternalCreatePending(want, time.Now())
1876-
meta.SetExternalCreateSucceeded(want, time.Now())
1877-
want.SetConditions(xpv1.ReconcileSuccess().WithObservedGeneration(42))
1878-
want.SetConditions(xpv1.Creating().WithObservedGeneration(42))
1879-
if diff := cmp.Diff(want, obj, test.EquateConditions(), cmpopts.EquateApproxTime(1*time.Second)); diff != "" {
1880-
reason := "Successful managed resource creation should be reported as a conditioned status."
1881-
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
1882-
}
1883-
return nil
1884-
}),
1885-
},
1886-
Scheme: fake.SchemeWith(&fake.LegacyManaged{}),
1887-
},
1888-
mg: resource.ManagedKind(fake.GVK(&fake.LegacyManaged{})),
1889-
o: []ReconcilerOption{
1890-
WithInitializers(),
1891-
WithManagementPolicies(),
1892-
WithReferenceResolver(ReferenceResolverFn(func(_ context.Context, _ resource.Managed) error { return nil })),
1893-
WithExternalConnector(&NopConnector{}),
1894-
WithCriticalAnnotationUpdater(CriticalAnnotationUpdateFn(func(_ context.Context, _ client.Object) error { return nil })),
1895-
WithFinalizer(resource.FinalizerFns{AddFinalizerFn: func(_ context.Context, _ resource.Object) error { return nil }}),
1896-
},
1897-
},
1898-
want: want{result: reconcile.Result{Requeue: true}},
1899-
},
19001861
"ManagementPolicyCreateCreateSuccessful": {
19011862
reason: "Successful managed resource creation using management policy Create should trigger a requeue after a short wait.",
19021863
args: args{
@@ -2129,53 +2090,6 @@ func TestReconciler(t *testing.T) {
21292090
},
21302091
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
21312092
},
2132-
"ManagementPolicyOrphanUpdateSuccessful": {
2133-
reason: "A successful managed resource update using management policies should trigger a requeue after a long wait.",
2134-
args: args{
2135-
m: &fake.Manager{
2136-
Client: &test.MockClient{
2137-
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
2138-
mg := asLegacyManaged(obj, 42)
2139-
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionOrphan})
2140-
return nil
2141-
}),
2142-
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, obj client.Object, _ ...client.SubResourceUpdateOption) error {
2143-
want := newLegacyManaged(42)
2144-
want.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionOrphan})
2145-
want.SetConditions(xpv1.ReconcileSuccess().WithObservedGeneration(42).WithObservedGeneration(42))
2146-
if diff := cmp.Diff(want, obj, test.EquateConditions()); diff != "" {
2147-
reason := "A successful managed resource update should be reported as a conditioned status."
2148-
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
2149-
}
2150-
return nil
2151-
}),
2152-
},
2153-
Scheme: fake.SchemeWith(&fake.LegacyManaged{}),
2154-
},
2155-
mg: resource.ManagedKind(fake.GVK(&fake.LegacyManaged{})),
2156-
o: []ReconcilerOption{
2157-
WithInitializers(),
2158-
WithManagementPolicies(),
2159-
WithReferenceResolver(ReferenceResolverFn(func(_ context.Context, _ resource.Managed) error { return nil })),
2160-
WithExternalConnector(ExternalConnectorFn(func(_ context.Context, _ resource.Managed) (ExternalClient, error) {
2161-
c := &ExternalClientFns{
2162-
ObserveFn: func(_ context.Context, _ resource.Managed) (ExternalObservation, error) {
2163-
return ExternalObservation{ResourceExists: true, ResourceUpToDate: false}, nil
2164-
},
2165-
UpdateFn: func(_ context.Context, _ resource.Managed) (ExternalUpdate, error) {
2166-
return ExternalUpdate{}, nil
2167-
},
2168-
DisconnectFn: func(_ context.Context) error {
2169-
return nil
2170-
},
2171-
}
2172-
return c, nil
2173-
})),
2174-
WithFinalizer(resource.FinalizerFns{AddFinalizerFn: func(_ context.Context, _ resource.Object) error { return nil }}),
2175-
},
2176-
},
2177-
want: want{result: reconcile.Result{RequeueAfter: defaultPollInterval}},
2178-
},
21792093
"ManagementPolicyUpdateUpdateSuccessful": {
21802094
reason: "A successful managed resource update using management policies should trigger a requeue after a long wait.",
21812095
args: args{
@@ -2492,14 +2406,6 @@ func TestLegacyManagementPoliciesResolverShouldCreate(t *testing.T) {
24922406
},
24932407
want: true,
24942408
},
2495-
"ManagementPoliciesEnabledHasCreateOrphan": {
2496-
reason: "Should return true if management policies are enabled and managementPolicies has action Orphan",
2497-
args: args{
2498-
managementPoliciesEnabled: true,
2499-
policy: xpv1.ManagementPolicies{xpv1.ManagementActionOrphan},
2500-
},
2501-
want: true,
2502-
},
25032409
"ManagementPoliciesEnabledActionNotAllowed": {
25042410
reason: "Should return false if management policies are enabled and managementPolicies does not have Create",
25052411
args: args{
@@ -2561,14 +2467,6 @@ func TestLegacyManagementPoliciesResolverShouldUpdate(t *testing.T) {
25612467
},
25622468
want: false,
25632469
},
2564-
"ManagementPoliciesEnabledHasUpdateOrphan": {
2565-
reason: "Should return true if management policies are enabled and managementPolicies has action Orphan",
2566-
args: args{
2567-
managementPoliciesEnabled: true,
2568-
policy: xpv1.ManagementPolicies{xpv1.ManagementActionOrphan},
2569-
},
2570-
want: true,
2571-
},
25722470
}
25732471
for name, tc := range cases {
25742472
t.Run(name, func(t *testing.T) {
@@ -2622,14 +2520,6 @@ func TestLegacyManagementPoliciesResolverShouldLateInitialize(t *testing.T) {
26222520
},
26232521
want: false,
26242522
},
2625-
"ManagementPoliciesEnabledHasLateInitializeOrphan": {
2626-
reason: "Should return true if management policies are enabled and managementPolicies has action Orphan",
2627-
args: args{
2628-
managementPoliciesEnabled: true,
2629-
policy: xpv1.ManagementPolicies{xpv1.ManagementActionOrphan},
2630-
},
2631-
want: true,
2632-
},
26332523
}
26342524
for name, tc := range cases {
26352525
t.Run(name, func(t *testing.T) {
@@ -2800,33 +2690,6 @@ func TestLegacyShouldDelete(t *testing.T) {
28002690
},
28012691
want: want{delete: false},
28022692
},
2803-
"DeletionDeleteManagementActionOrphan": {
2804-
reason: "Should orphan if management policies are enabled and deletion policy is set to Delete and management policy does not have action Delete.",
2805-
args: args{
2806-
managementPoliciesEnabled: true,
2807-
managed: &fake.LegacyManaged{
2808-
Orphanable: fake.Orphanable{
2809-
Policy: xpv1.DeletionDelete,
2810-
},
2811-
Manageable: fake.Manageable{
2812-
Policy: xpv1.ManagementPolicies{xpv1.ManagementActionOrphan},
2813-
},
2814-
},
2815-
},
2816-
want: want{delete: false},
2817-
},
2818-
"DeletionManagementActionOrphan": {
2819-
reason: "Should orphan if management policies are enabled and deletion policy is not set and management policy does not have action Delete.",
2820-
args: args{
2821-
managementPoliciesEnabled: true,
2822-
managed: &fake.LegacyManaged{
2823-
Manageable: fake.Manageable{
2824-
Policy: xpv1.ManagementPolicies{xpv1.ManagementActionOrphan},
2825-
},
2826-
},
2827-
},
2828-
want: want{delete: false},
2829-
},
28302693
}
28312694
for name, tc := range cases {
28322695
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)