Skip to content

Commit 3ff336a

Browse files
committed
Delete native P&T based Usage E2E test
It's functionally identical (no pun intended) to the variant that uses functions, but the native version has a nasty bug. When it patches the MR it removes the MR's finalizer, which causes the XR and MR controllers to fight. This is bad when realtime compositions are enabled. We could potentially fix the native P&T variant (e.g. by patching in the finalizer) but I don't think it's worth it. Apart from this very specific scenario where we artificially set a finalizer to block the delete, the composition implementation shouldn't matter. Given native P&T is deprecated let's drop it and save some time in E2E runs. Signed-off-by: Nic Cope <[email protected]>
1 parent af29be3 commit 3ff336a

File tree

8 files changed

+79
-265
lines changed

8 files changed

+79
-265
lines changed

test/e2e/manifests/apiextensions/usage/composition-pipeline/claim.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/e2e/manifests/apiextensions/usage/composition-pipeline/setup/composition.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/e2e/manifests/apiextensions/usage/composition-pipeline/setup/definition.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/e2e/manifests/apiextensions/usage/composition-pipeline/setup/provider.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/e2e/manifests/apiextensions/usage/composition-pipeline/composition-updated.yaml renamed to test/e2e/manifests/apiextensions/usage/composition/composition-updated.yaml

File renamed without changes.

test/e2e/manifests/apiextensions/usage/composition/setup/composition.yaml

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,82 @@ spec:
66
compositeTypeRef:
77
apiVersion: nop.example.org/v1alpha1
88
kind: XNopResource
9-
resources:
10-
- name: used-resource
11-
base:
12-
apiVersion: nop.crossplane.io/v1alpha1
13-
kind: NopResource
14-
metadata:
15-
labels:
16-
usage: used
17-
spec:
18-
forProvider:
19-
conditionAfter:
20-
- conditionType: "Synced"
21-
conditionStatus: "True"
22-
time: "5s"
23-
- conditionType: "Ready"
24-
conditionStatus: "True"
25-
time: "10s"
26-
- name: using-resource
27-
base:
28-
apiVersion: nop.crossplane.io/v1alpha1
29-
kind: NopResource
30-
metadata:
31-
# We are delaying deletion of using resource with this finalizer. This is to ensure that the used resource is
32-
# not deleted before the using resource. Imagine a scenario where a Release resource using a Cluster resource
33-
# where we expect the Cluster resource not to be deleted until the Release resource is deleted. We are mimicking
34-
# this behavior with the help of a finalizer on a NopResource.
35-
finalizers:
36-
- delay-deletion-of-using-resource
37-
labels:
38-
usage: using
39-
spec:
40-
forProvider:
41-
conditionAfter:
42-
- conditionType: "Synced"
43-
conditionStatus: "True"
44-
time: "5s"
45-
- conditionType: "Ready"
46-
conditionStatus: "True"
47-
time: "10s"
48-
- name: usage-resource
49-
base:
50-
apiVersion: apiextensions.crossplane.io/v1beta1
51-
kind: Usage
52-
spec:
53-
of:
54-
apiVersion: nop.crossplane.io/v1alpha1
55-
kind: NopResource
56-
resourceSelector:
57-
matchControllerRef: true
58-
matchLabels:
59-
usage: used
60-
by:
61-
apiVersion: nop.crossplane.io/v1alpha1
62-
kind: NopResource
63-
resourceSelector:
64-
matchControllerRef: true
65-
matchLabels:
66-
usage: using
9+
mode: Pipeline
10+
pipeline:
11+
- step: be-a-dummy
12+
functionRef:
13+
name: function-dummy
14+
input:
15+
apiVersion: dummy.fn.crossplane.io/v1beta1
16+
kind: Response
17+
# This is a YAML-serialized RunFunctionResponse. function-dummy will
18+
# overlay the desired state on any that was passed into it.
19+
response:
20+
desired:
21+
resources:
22+
used-resource:
23+
resource:
24+
apiVersion: nop.crossplane.io/v1alpha1
25+
kind: NopResource
26+
metadata:
27+
labels:
28+
usage: used
29+
spec:
30+
forProvider:
31+
conditionAfter:
32+
- conditionType: "Synced"
33+
conditionStatus: "True"
34+
time: "5s"
35+
- conditionType: "Ready"
36+
conditionStatus: "True"
37+
time: "10s"
38+
using-resource:
39+
resource:
40+
apiVersion: nop.crossplane.io/v1alpha1
41+
kind: NopResource
42+
metadata:
43+
# We are delaying deletion of using resource with this finalizer. This is to ensure that the used resource is
44+
# not deleted before the using resource. Imagine a scenario where a Release resource using a Cluster resource
45+
# where we expect the Cluster resource not to be deleted until the Release resource is deleted. We are mimicking
46+
# this behavior with the help of a finalizer on a NopResource.
47+
finalizers:
48+
- delay-deletion-of-using-resource
49+
labels:
50+
usage: using
51+
spec:
52+
forProvider:
53+
conditionAfter:
54+
- conditionType: "Synced"
55+
conditionStatus: "True"
56+
time: "5s"
57+
- conditionType: "Ready"
58+
conditionStatus: "True"
59+
time: "10s"
60+
usage-resource:
61+
resource:
62+
apiVersion: apiextensions.crossplane.io/v1beta1
63+
kind: Usage
64+
metadata:
65+
labels:
66+
version: initial
67+
spec:
68+
of:
69+
apiVersion: nop.crossplane.io/v1alpha1
70+
kind: NopResource
71+
resourceSelector:
72+
matchControllerRef: true
73+
matchLabels:
74+
usage: used
75+
by:
76+
apiVersion: nop.crossplane.io/v1alpha1
77+
kind: NopResource
78+
resourceSelector:
79+
matchControllerRef: true
80+
matchLabels:
81+
usage: using
82+
results:
83+
- severity: SEVERITY_NORMAL
84+
message: "I am doing a compose!"
85+
- step: detect-readiness
86+
functionRef:
87+
name: function-auto-ready

test/e2e/manifests/apiextensions/usage/composition-pipeline/setup/functions.yaml renamed to test/e2e/manifests/apiextensions/usage/composition/setup/functions.yaml

File renamed without changes.

test/e2e/usage_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -100,83 +100,6 @@ func TestUsageComposition(t *testing.T) {
100100
Kind: "Usage",
101101
}))
102102

103-
environment.Test(t,
104-
features.NewWithDescription(t.Name(), "Tests scenarios for Crossplane's `Usage` resource as part of a composition.").
105-
WithLabel(LabelStage, LabelStageBeta).
106-
WithLabel(LabelArea, LabelAreaAPIExtensions).
107-
WithLabel(LabelSize, LabelSizeSmall).
108-
WithLabel(config.LabelTestSuite, config.TestSuiteDefault).
109-
WithSetup("PrerequisitesAreCreated", funcs.AllOf(
110-
funcs.ApplyResources(FieldManager, manifests, "setup/*.yaml"),
111-
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "setup/*.yaml"),
112-
funcs.ResourcesHaveConditionWithin(1*time.Minute, manifests, "setup/definition.yaml", apiextensionsv1.WatchingComposite()),
113-
funcs.ResourcesHaveConditionWithin(2*time.Minute, manifests, "setup/provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
114-
)).
115-
Assess("ClaimCreatedAndReady", funcs.AllOf(
116-
funcs.ApplyResources(FieldManager, manifests, "claim.yaml"),
117-
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "claim.yaml"),
118-
funcs.ResourcesHaveConditionWithin(5*time.Minute, manifests, "claim.yaml", xpv1.Available()),
119-
)).
120-
Assess("UsedResourceHasInUseLabel", funcs.AllOf(
121-
funcs.ComposedResourcesHaveFieldValueWithin(1*time.Minute, manifests, "claim.yaml", "metadata.labels[crossplane.io/in-use]", "true", func(object k8s.Object) bool {
122-
return object.GetLabels()["usage"] == "used"
123-
}),
124-
)).
125-
Assess("ClaimDeleted", funcs.AllOf(
126-
funcs.DeleteResources(manifests, "claim.yaml"),
127-
funcs.ResourcesDeletedWithin(1*time.Minute, manifests, "claim.yaml"),
128-
)).
129-
// NOTE(turkenh): At this point, the claim is deleted and hence the
130-
// garbage collector started attempting to delete all composed
131-
// resources. With the help of a finalizer (namely
132-
// `delay-deletion-of-using-resource`, see in the composition),
133-
// we know that the using resource is still there and hence the
134-
// deletion of the used resource should be blocked. We will assess
135-
// that below.
136-
Assess("OthersDeletedExceptUsed", funcs.AllOf(
137-
// Using resource should have a deletion timestamp (i.e. deleted by the garbage collector).
138-
funcs.ListedResourcesValidatedWithin(1*time.Minute, nopList, 1, func(object k8s.Object) bool {
139-
return object.GetDeletionTimestamp() != nil
140-
}, resources.WithLabelSelector(labels.FormatLabels(map[string]string{"usage": "using"}))),
141-
// Usage resource should not have a deletion timestamp since it is owned by the using resource.
142-
funcs.ListedResourcesValidatedWithin(1*time.Minute, usageList, 1, func(object k8s.Object) bool {
143-
return object.GetDeletionTimestamp() == nil
144-
}),
145-
// Used resource should not have a deletion timestamp since it is still in use.
146-
funcs.ListedResourcesValidatedWithin(1*time.Minute, nopList, 1, func(object k8s.Object) bool {
147-
return object.GetDeletionTimestamp() == nil
148-
}, resources.WithLabelSelector(labels.FormatLabels(map[string]string{"usage": "used"}))),
149-
)).
150-
Assess("UsingDeletedAllGone", funcs.AllOf(
151-
// Remove the finalizer from the using resource.
152-
funcs.ListedResourcesModifiedWith(nopList, 1, func(object k8s.Object) {
153-
object.SetFinalizers(nil)
154-
}, resources.WithLabelSelector(labels.FormatLabels(map[string]string{"usage": "using"}))),
155-
// All composed resources should now be deleted including the Usage itself.
156-
funcs.ListedResourcesDeletedWithin(2*time.Minute, nopList),
157-
funcs.ListedResourcesDeletedWithin(2*time.Minute, usageList),
158-
)).
159-
WithTeardown("DeletePrerequisites", funcs.AllOf(
160-
funcs.DeleteResources(manifests, "setup/*.yaml"),
161-
funcs.ResourcesDeletedWithin(3*time.Minute, manifests, "setup/*.yaml"),
162-
)).
163-
// Disable our feature flag.
164-
WithTeardown("DisableAlphaUsages", funcs.AllOf(
165-
funcs.AsFeaturesFunc(environment.HelmUpgradeCrossplaneToBase()),
166-
funcs.ReadyToTestWithin(1*time.Minute, namespace),
167-
)).
168-
Feature(),
169-
)
170-
}
171-
172-
func TestUsageCompositionWithPipeline(t *testing.T) {
173-
manifests := "test/e2e/manifests/apiextensions/usage/composition-pipeline"
174-
175-
usageList := composed.NewList(composed.FromReferenceToList(corev1.ObjectReference{
176-
APIVersion: "apiextensions.crossplane.io/v1alpha1",
177-
Kind: "Usage",
178-
}))
179-
180103
environment.Test(t,
181104
features.NewWithDescription(t.Name(), "Tests scenarios for Crossplane's `Usage` resource as part of a composition pipeline and decomposed properly.").
182105
WithLabel(LabelStage, LabelStageBeta).

0 commit comments

Comments
 (0)