Skip to content

Commit 0d806ba

Browse files
authored
Merge pull request crossplane#6160 from turkenh/rollback-e2e
e2e: cover downgrades in the lifecycle test case
2 parents 4b3dd0d + 99443b0 commit 0d806ba

File tree

2 files changed

+92
-11
lines changed

2 files changed

+92
-11
lines changed

test/e2e/config/environment.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,53 @@ func (e *Environment) HelmInstallBaseCrossplane() env.Func {
193193
// HelmInstallPriorCrossplane returns a features.Func that installs prior
194194
// Crossplane version from the stable Helm chart repository.
195195
func (e *Environment) HelmInstallPriorCrossplane(namespace, release string) env.Func {
196-
opts := []helm.Option{
197-
helm.WithNamespace(namespace),
198-
helm.WithName(release),
199-
helm.WithChart("crossplane-stable/crossplane"),
200-
helm.WithArgs("--create-namespace", "--wait"),
201-
}
202-
if e.priorCrossplaneVersion != nil && *e.priorCrossplaneVersion != "" {
203-
opts = append(opts, helm.WithArgs("--version", *e.priorCrossplaneVersion))
204-
}
205196
return funcs.EnvFuncs(
206197
funcs.HelmRepo(
207198
helm.WithArgs("add"),
208199
helm.WithArgs("crossplane-stable"),
209200
helm.WithArgs("https://charts.crossplane.io/stable"),
210201
),
211-
funcs.HelmInstall(
212-
opts...,
202+
funcs.HelmInstall(e.helmOptionsForPriorCrossplane(namespace, release)...),
203+
)
204+
}
205+
206+
// HelmUpgradePriorCrossplane returns a features.Func that upgrades to prior
207+
// Crossplane version from the stable Helm chart repository.
208+
func (e *Environment) HelmUpgradePriorCrossplane(namespace, release string) env.Func {
209+
// We need to reset the values to ensure that the values from the
210+
// chart are used. Otherwise, the values from the previous install
211+
// will be used which overrides the image with the one from the
212+
// current build since we don't have any overrides here.
213+
// https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e
214+
opts := append(e.helmOptionsForPriorCrossplane(namespace, release), helm.WithArgs("--reset-values"))
215+
return funcs.EnvFuncs(
216+
funcs.HelmRepo(
217+
helm.WithArgs("add"),
218+
helm.WithArgs("crossplane-stable"),
219+
helm.WithArgs("https://charts.crossplane.io/stable"),
213220
),
221+
funcs.HelmUpgrade(opts...),
214222
)
215223
}
216224

225+
// helmOptionsForPriorCrossplane returns the helm install/upgrade options for
226+
// the prior Crossplane version.
227+
func (e *Environment) helmOptionsForPriorCrossplane(namespace, release string) []helm.Option {
228+
opts := []helm.Option{
229+
helm.WithNamespace(namespace),
230+
helm.WithName(release),
231+
helm.WithChart("crossplane-stable/crossplane"),
232+
helm.WithArgs(
233+
"--create-namespace",
234+
"--wait",
235+
),
236+
}
237+
if e.priorCrossplaneVersion != nil && *e.priorCrossplaneVersion != "" {
238+
opts = append(opts, helm.WithArgs("--version", *e.priorCrossplaneVersion))
239+
}
240+
return opts
241+
}
242+
217243
// getSuiteInstallOpts returns the helm install options for the specified
218244
// suite, appending additional specified ones.
219245
func (e *Environment) getSuiteInstallOpts(suite string, extra ...helm.Option) []helm.Option {

test/e2e/install_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,61 @@ func TestCrossplaneLifecycle(t *testing.T) {
9090
funcs.ResourceDeletedWithin(3*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
9191
)).
9292
Feature(),
93+
features.NewWithDescription(t.Name()+"Downgrade", "Test that it's possible to downgrade Crossplane to the most recent stable Helm chart from the one we're testing, even when a claim exists. This expects Crossplane not to be installed.").
94+
WithLabel(LabelArea, LabelAreaLifecycle).
95+
WithLabel(LabelSize, LabelSizeSmall).
96+
WithLabel(config.LabelTestSuite, config.TestSuiteDefault).
97+
// We expect Crossplane to have been uninstalled first
98+
Assess("CrossplaneIsNotInstalled", funcs.AllOf(
99+
funcs.ResourceDeletedWithin(1*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
100+
funcs.ResourcesDeletedWithin(3*time.Minute, crdsDir, "*.yaml"),
101+
)).
102+
Assess("InstallCrossplane", funcs.AllOf(
103+
funcs.AsFeaturesFunc(envfuncs.CreateNamespace(namespace)),
104+
funcs.AsFeaturesFunc(environment.HelmInstallBaseCrossplane()),
105+
funcs.ReadyToTestWithin(1*time.Minute, namespace),
106+
)).
107+
Assess("CreateClaimPrerequisites", funcs.AllOf(
108+
funcs.ApplyResources(FieldManager, manifests, "setup/*.yaml"),
109+
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "setup/*.yaml"),
110+
)).
111+
Assess("XRDIsEstablished",
112+
funcs.ResourcesHaveConditionWithin(1*time.Minute, manifests, "setup/definition.yaml", apiextensionsv1.WatchingComposite())).
113+
Assess("ProviderIsReady",
114+
funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "setup/provider.yaml", pkgv1.Healthy(), pkgv1.Active())).
115+
Assess("CreateClaim", funcs.AllOf(
116+
funcs.ApplyResources(FieldManager, manifests, "claim.yaml"),
117+
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "claim.yaml"),
118+
)).
119+
Assess("ClaimIsAvailable", funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "claim.yaml", xpv1.Available())).
120+
Assess("DowngradeCrossplane", funcs.AllOf(
121+
funcs.AsFeaturesFunc(environment.HelmUpgradePriorCrossplane(namespace, helmReleaseName)),
122+
funcs.ReadyToTestWithin(1*time.Minute, namespace),
123+
)).
124+
Assess("CoreDeploymentIsAvailable", funcs.DeploymentBecomesAvailableWithin(1*time.Minute, namespace, "crossplane")).
125+
Assess("RBACManagerDeploymentIsAvailable", funcs.DeploymentBecomesAvailableWithin(1*time.Minute, namespace, "crossplane-rbac-manager")).
126+
Assess("CoreCRDsAreEstablished", funcs.ResourcesHaveConditionWithin(1*time.Minute, crdsDir, "*.yaml", funcs.CRDInitialNamesAccepted())).
127+
Assess("ClaimIsStillAvailable", funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "claim.yaml", xpv1.Available())).
128+
Assess("DeleteClaim", funcs.AllOf(
129+
funcs.DeleteResources(manifests, "claim.yaml"),
130+
funcs.ResourcesDeletedWithin(2*time.Minute, manifests, "claim.yaml"),
131+
)).
132+
WithTeardown("DeletePrerequisites", funcs.ResourcesDeletedAfterListedAreGone(3*time.Minute, manifests, "setup/*.yaml", nopList)).
133+
// Uninstalling the Crossplane Helm chart doesn't remove its CRDs. We
134+
// want to make sure they can be deleted cleanly. If they can't, it's a
135+
// sign something they define might have stuck around.
136+
WithTeardown("DeleteCrossplaneCRDs", funcs.AllOf(
137+
funcs.DeleteResources(crdsDir, "*.yaml"),
138+
funcs.ResourcesDeletedWithin(3*time.Minute, crdsDir, "*.yaml"),
139+
)).
140+
// Uninstalling the Crossplane Helm chart doesn't remove the namespace
141+
// it was installed to either. We want to make sure it can be deleted
142+
// cleanly.
143+
WithTeardown("DeleteCrossplaneNamespace", funcs.AllOf(
144+
funcs.AsFeaturesFunc(envfuncs.DeleteNamespace(namespace)),
145+
funcs.ResourceDeletedWithin(3*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
146+
)).
147+
Feature(),
93148
features.NewWithDescription(t.Name()+"Upgrade", "Test that it's possible to upgrade Crossplane from the most recent stable Helm chart to the one we're testing, even when a claim exists. This expects Crossplane not to be installed.").
94149
WithLabel(LabelArea, LabelAreaLifecycle).
95150
WithLabel(LabelSize, LabelSizeSmall).

0 commit comments

Comments
 (0)