Skip to content

Commit 7504c3e

Browse files
committed
Revert "Merge pull request #873 from nokia/add_mustcreate_policy"
This reverts commit af8c3fb, reversing changes made to a4cdda4. Signed-off-by: lsviben <sviben.lovro@gmail.com>
1 parent e7dec5e commit 7504c3e

File tree

8 files changed

+2
-314
lines changed

8 files changed

+2
-314
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
25+
// +kubebuilder:validation:Enum=Observe;Create;Update;Delete;LateInitialize;*
2626
type ManagementAction string
2727

2828
const (
@@ -49,10 +49,6 @@ const (
4949
// ManagementActionAll means that all of the above actions will be taken
5050
// by the Crossplane controllers.
5151
ManagementActionAll ManagementAction = "*"
52-
53-
// ManagementActionMustCreate means that the external resource MUST be created
54-
// by the managed resource and if it already exists an error condition is raised.
55-
ManagementActionMustCreate ManagementAction = "MustCreate"
5652
)
5753

5854
// 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
@@ -52,10 +52,6 @@ const (
5252
// ManagementActionAll means that all of the above actions will be taken
5353
// by the Crossplane controllers.
5454
ManagementActionAll = common.ManagementActionAll
55-
56-
// ManagementActionMustCreate means that the external resource must be created
57-
// by this MR and if it already exists an error condition is raised and no further processing is executed.
58-
ManagementActionMustCreate = common.ManagementActionMustCreate
5955
)
6056

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

pkg/meta/meta.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,6 @@ func ExternalCreateSucceededDuring(o metav1.Object, d time.Duration) bool {
362362
return time.Since(t) < d
363363
}
364364

365-
// ExternalCreateNotStarted returns true if the external resource was detected
366-
// during the initial Observe phase and was not created by this managed resource.
367-
func ExternalCreateNotStarted(o metav1.Object) bool {
368-
pending := GetExternalCreatePending(o)
369-
succeeded := GetExternalCreateSucceeded(o)
370-
failed := GetExternalCreateFailed(o)
371-
372-
if pending.IsZero() && succeeded.IsZero() && failed.IsZero() {
373-
return true
374-
}
375-
376-
return false
377-
}
378-
379365
// IsPaused returns true if the object has the AnnotationKeyReconciliationPaused
380366
// annotation set to `true`.
381367
func IsPaused(o metav1.Object) bool {

pkg/meta/meta_test.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,66 +1228,3 @@ func TestIsPaused(t *testing.T) {
12281228
})
12291229
}
12301230
}
1231-
1232-
func TestExternalCreateNotStarted(t *testing.T) {
1233-
type args struct {
1234-
o metav1.Object
1235-
}
1236-
1237-
cases := map[string]struct {
1238-
args args
1239-
want bool
1240-
}{
1241-
"CreatePending": {
1242-
args: args{
1243-
o: func() metav1.Object {
1244-
o := &corev1.Pod{}
1245-
t := time.Now().Add(-30 * time.Second)
1246-
SetExternalCreatePending(o, t)
1247-
1248-
return o
1249-
}(),
1250-
},
1251-
want: false,
1252-
},
1253-
"CreateFailed": {
1254-
args: args{
1255-
o: func() metav1.Object {
1256-
o := &corev1.Pod{}
1257-
t := time.Now().Add(-30 * time.Second)
1258-
SetExternalCreateFailed(o, t)
1259-
1260-
return o
1261-
}(),
1262-
},
1263-
want: false,
1264-
},
1265-
"SuccessfullyCreated": {
1266-
args: args{
1267-
o: func() metav1.Object {
1268-
o := &corev1.Pod{}
1269-
t := time.Now().Add(-2 * time.Minute)
1270-
SetExternalCreateSucceeded(o, t)
1271-
1272-
return o
1273-
}(),
1274-
},
1275-
want: false,
1276-
},
1277-
"NotStarted": {
1278-
args: args{
1279-
o: &corev1.Pod{},
1280-
},
1281-
want: true,
1282-
},
1283-
}
1284-
1285-
for name, tc := range cases {
1286-
t.Run(name, func(t *testing.T) {
1287-
got := ExternalCreateNotStarted(tc.args.o)
1288-
if diff := cmp.Diff(tc.want, got); diff != "" {
1289-
t.Errorf("ExternalCreateNotStarted(...): -want, +got:\n%s", diff)
1290-
}
1291-
})
1292-
}
1293-
}

pkg/reconciler/managed/policies.go

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ func defaultSupportedManagementPolicies() []sets.Set[xpv1.ManagementAction] {
6060
sets.New[xpv1.ManagementAction](xpv1.ManagementActionAll),
6161
// All actions explicitly set, the same as default.
6262
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize, xpv1.ManagementActionDelete),
63-
// All actions explicitly set with MustCreate instead of Create.
64-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize, xpv1.ManagementActionDelete),
6563
// ObserveOnly, just observe action is done, the external resource is
6664
// considered as read-only.
6765
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve),
@@ -71,55 +69,29 @@ func defaultSupportedManagementPolicies() []sets.Set[xpv1.ManagementAction] {
7169
// No LateInitialize filling in the spec.forProvider, allowing some
7270
// external resource fields to be managed externally.
7371
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionDelete),
74-
// No LateInitialize filling in the spec.forProvider, allowing some
75-
// external resource fields to be managed externally. With MustCreate.
76-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionDelete),
7772
// No Delete, the external resource is not deleted when the managed
7873
// resource is deleted.
7974
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize),
80-
// No Delete, the external resource is not deleted when the managed
81-
// resource is deleted. With MustCreate.
82-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionUpdate, xpv1.ManagementActionLateInitialize),
8375
// No Delete and no LateInitialize, the external resource is not deleted
8476
// when the managed resource is deleted and the spec.forProvider is not
8577
// late initialized.
8678
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionUpdate),
87-
// No Delete and no LateInitialize, the external resource is not deleted
88-
// when the managed resource is deleted and the spec.forProvider is not
89-
// late initialized. With MustCreate.
90-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionUpdate),
9179
// No Update, the external resource is not updated when the managed
9280
// resource is updated. Useful for immutable external resources.
9381
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionDelete, xpv1.ManagementActionLateInitialize),
94-
// No Update, the external resource is not updated when the managed
95-
// resource is updated. Useful for immutable external resources. With MustCreate.
96-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete, xpv1.ManagementActionLateInitialize),
9782
// No Update and no Delete, the external resource is not updated
9883
// when the managed resource is updated and the external resource
9984
// is not deleted when the managed resource is deleted.
10085
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionLateInitialize),
101-
// No Update and no Delete, the external resource is not updated
102-
// when the managed resource is updated and the external resource
103-
// is not deleted when the managed resource is deleted. With MustCreate.
104-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionLateInitialize),
10586
// No Update and no LateInitialize, the external resource is not updated
10687
// when the managed resource is updated and the spec.forProvider is not
10788
// late initialized.
10889
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate, xpv1.ManagementActionDelete),
109-
// No Update and no LateInitialize, the external resource is not updated
110-
// when the managed resource is updated and the spec.forProvider is not
111-
// late initialized. With MustCreate.
112-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete),
11390
// No Update, no Delete and no LateInitialize, the external resource is
11491
// not updated when the managed resource is updated, the external resource
11592
// is not deleted when the managed resource is deleted and the
11693
// spec.forProvider is not late initialized.
11794
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionCreate),
118-
// No Update, no Delete and no LateInitialize, the external resource is
119-
// not updated when the managed resource is updated, the external resource
120-
// is not deleted when the managed resource is deleted and the
121-
// spec.forProvider is not late initialized. With MustCreate.
122-
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate),
12395
// Like ObserveOnly, but the external resource is deleted when the
12496
// managed resource is deleted.
12597
sets.New[xpv1.ManagementAction](xpv1.ManagementActionObserve, xpv1.ManagementActionDelete),
@@ -217,18 +189,7 @@ func (m *ManagementPoliciesResolver) ShouldCreate() bool {
217189
return true
218190
}
219191

220-
return m.managementPolicies.HasAny(xpv1.ManagementActionCreate, xpv1.ManagementActionAll, xpv1.ManagementActionMustCreate)
221-
}
222-
223-
// MustCreate returns true if the Create action is required. If the resource already exists an error will
224-
// be raised in the reconciler.
225-
// If the management policy feature is disabled, it returns false.
226-
func (m *ManagementPoliciesResolver) MustCreate() bool {
227-
if !m.enabled {
228-
return false
229-
}
230-
231-
return m.managementPolicies.Has(xpv1.ManagementActionMustCreate)
192+
return m.managementPolicies.HasAny(xpv1.ManagementActionCreate, xpv1.ManagementActionAll)
232193
}
233194

234195
// ShouldUpdate returns true if the Update action is allowed.

pkg/reconciler/managed/reconciler.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ const (
7070
errExternalResourceNotExist = "external resource does not exist"
7171

7272
errManagedNotImplemented = "managed resource does not implement connection details"
73-
74-
errMustCreate = "managed resource has mustcreate policy but external resource already exists"
7573
)
7674

7775
// Event reasons.
@@ -117,8 +115,6 @@ type ManagementPoliciesChecker interface { //nolint:interfacebloat // This has t
117115
ShouldOnlyObserve() bool
118116
// ShouldCreate returns true if the Create action is allowed.
119117
ShouldCreate() bool
120-
// MustCreate returns true if the create action is required to be executed
121-
MustCreate() bool
122118
// ShouldLateInitialize returns true if the LateInitialize action is
123119
// allowed.
124120
ShouldLateInitialize() bool
@@ -1148,16 +1144,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (resu
11481144
return reconcile.Result{Requeue: true}, errors.Wrap(r.client.Status().Update(ctx, managed), errUpdateManagedStatus)
11491145
}
11501146

1151-
// If the resource already exists, the MustCreate policy is set, and there are no create annotations then
1152-
// this MR did not create the resource and an error is raised.
1153-
if observation.ResourceExists && policy.MustCreate() && meta.ExternalCreateNotStarted(managed) {
1154-
log.Debug(errMustCreate)
1155-
record.Event(managed, event.Warning(reasonCannotCreate, errors.New(errMustCreate)))
1156-
status.MarkConditions(xpv1.Creating(), xpv1.ReconcileError(errors.New(errMustCreate)))
1157-
1158-
return reconcile.Result{Requeue: false}, errors.Wrap(r.client.Status().Update(ctx, managed), errUpdateManagedStatus)
1159-
}
1160-
11611147
// If this resource has a non-zero creation grace period we want to wait
11621148
// for that period to expire before we trust that the resource really
11631149
// doesn't exist. This is because some external APIs are eventually

pkg/reconciler/managed/reconciler_legacy_test.go

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,93 +1900,6 @@ func TestReconciler(t *testing.T) {
19001900
},
19011901
want: want{result: reconcile.Result{Requeue: true}},
19021902
},
1903-
"ManagementPolicyMustCreateCreateSuccessful": {
1904-
reason: "Successful managed resource creation using management policy MustCreate should trigger a requeue after a short wait.",
1905-
args: args{
1906-
m: &fake.Manager{
1907-
Client: &test.MockClient{
1908-
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
1909-
mg := asLegacyManaged(obj, 42)
1910-
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete})
1911-
return nil
1912-
}),
1913-
MockUpdate: test.NewMockUpdateFn(nil),
1914-
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, obj client.Object, _ ...client.SubResourceUpdateOption) error {
1915-
want := newLegacyManaged(42)
1916-
want.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete})
1917-
meta.SetExternalCreatePending(want, time.Now())
1918-
meta.SetExternalCreateSucceeded(want, time.Now())
1919-
want.SetConditions(xpv1.ReconcileSuccess().WithObservedGeneration(42))
1920-
want.SetConditions(xpv1.Creating().WithObservedGeneration(42))
1921-
if diff := cmp.Diff(want, obj, test.EquateConditions(), cmpopts.EquateApproxTime(1*time.Second)); diff != "" {
1922-
reason := "Successful managed resource creation should be reported as a conditioned status."
1923-
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
1924-
}
1925-
return nil
1926-
}),
1927-
},
1928-
Scheme: fake.SchemeWith(&fake.LegacyManaged{}),
1929-
},
1930-
mg: resource.ManagedKind(fake.GVK(&fake.LegacyManaged{})),
1931-
o: []ReconcilerOption{
1932-
WithInitializers(),
1933-
WithManagementPolicies(),
1934-
WithReferenceResolver(ReferenceResolverFn(func(_ context.Context, _ resource.Managed) error { return nil })),
1935-
WithExternalConnector(&NopConnector{}),
1936-
WithCriticalAnnotationUpdater(CriticalAnnotationUpdateFn(func(_ context.Context, _ client.Object) error { return nil })),
1937-
WithFinalizer(resource.FinalizerFns{AddFinalizerFn: func(_ context.Context, _ resource.Object) error { return nil }}),
1938-
},
1939-
},
1940-
want: want{result: reconcile.Result{Requeue: true}},
1941-
},
1942-
"ResourceExistsMustCreateError": {
1943-
reason: "When a resource exists and the policy is MustCreate an error condition should be raised.",
1944-
args: args{
1945-
m: &fake.Manager{
1946-
Client: &test.MockClient{
1947-
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
1948-
mg := asLegacyManaged(obj, 42)
1949-
mg.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete})
1950-
return nil
1951-
}),
1952-
MockStatusUpdate: test.MockSubResourceUpdateFn(func(_ context.Context, obj client.Object, _ ...client.SubResourceUpdateOption) error {
1953-
want := newLegacyManaged(42)
1954-
want.SetManagementPolicies(xpv1.ManagementPolicies{xpv1.ManagementActionObserve, xpv1.ManagementActionMustCreate, xpv1.ManagementActionDelete})
1955-
want.SetConditions(xpv1.Creating().WithObservedGeneration(42), xpv1.ReconcileError(errors.New(errMustCreate)).WithObservedGeneration(42).WithObservedGeneration(42))
1956-
if diff := cmp.Diff(want, obj, test.EquateConditions()); diff != "" {
1957-
reason := "With MustCreate, a successful managed resource observation with no creation annotations should be reported as an error condition."
1958-
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
1959-
}
1960-
return nil
1961-
}),
1962-
},
1963-
Scheme: fake.SchemeWith(&fake.LegacyManaged{}),
1964-
},
1965-
mg: resource.ManagedKind(fake.GVK(&fake.LegacyManaged{})),
1966-
o: []ReconcilerOption{
1967-
WithInitializers(),
1968-
WithManagementPolicies(),
1969-
WithExternalConnector(ExternalConnectorFn(func(_ context.Context, _ resource.Managed) (ExternalClient, error) {
1970-
c := &ExternalClientFns{
1971-
ObserveFn: func(_ context.Context, _ resource.Managed) (ExternalObservation, error) {
1972-
return ExternalObservation{ResourceExists: true}, nil
1973-
},
1974-
DisconnectFn: func(_ context.Context) error {
1975-
return nil
1976-
},
1977-
}
1978-
return c, nil
1979-
})),
1980-
withLocalConnectionPublishers(LocalConnectionPublisherFns{
1981-
PublishConnectionFn: func(_ context.Context, _ resource.LocalConnectionSecretOwner, _ ConnectionDetails) (bool, error) {
1982-
return false, nil
1983-
},
1984-
}),
1985-
WithFinalizer(resource.FinalizerFns{AddFinalizerFn: func(_ context.Context, _ resource.Object) error { return nil }}),
1986-
},
1987-
},
1988-
want: want{result: reconcile.Result{Requeue: false}},
1989-
},
19901903
"ManagementPolicyImmutable": {
19911904
reason: "Successful reconciliation skipping update should trigger a requeue after a long wait.",
19921905
args: args{

0 commit comments

Comments
 (0)