Skip to content

Commit

Permalink
Merge pull request crossplane#6160 from turkenh/rollback-e2e
Browse files Browse the repository at this point in the history
e2e: cover downgrades in the lifecycle test case
  • Loading branch information
turkenh authored Dec 6, 2024
2 parents 4b3dd0d + 99443b0 commit 0d806ba
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 11 deletions.
48 changes: 37 additions & 11 deletions test/e2e/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,53 @@ func (e *Environment) HelmInstallBaseCrossplane() env.Func {
// HelmInstallPriorCrossplane returns a features.Func that installs prior
// Crossplane version from the stable Helm chart repository.
func (e *Environment) HelmInstallPriorCrossplane(namespace, release string) env.Func {
opts := []helm.Option{
helm.WithNamespace(namespace),
helm.WithName(release),
helm.WithChart("crossplane-stable/crossplane"),
helm.WithArgs("--create-namespace", "--wait"),
}
if e.priorCrossplaneVersion != nil && *e.priorCrossplaneVersion != "" {
opts = append(opts, helm.WithArgs("--version", *e.priorCrossplaneVersion))
}
return funcs.EnvFuncs(
funcs.HelmRepo(
helm.WithArgs("add"),
helm.WithArgs("crossplane-stable"),
helm.WithArgs("https://charts.crossplane.io/stable"),
),
funcs.HelmInstall(
opts...,
funcs.HelmInstall(e.helmOptionsForPriorCrossplane(namespace, release)...),
)
}

// HelmUpgradePriorCrossplane returns a features.Func that upgrades to prior
// Crossplane version from the stable Helm chart repository.
func (e *Environment) HelmUpgradePriorCrossplane(namespace, release string) env.Func {
// We need to reset the values to ensure that the values from the
// chart are used. Otherwise, the values from the previous install
// will be used which overrides the image with the one from the
// current build since we don't have any overrides here.
// https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e
opts := append(e.helmOptionsForPriorCrossplane(namespace, release), helm.WithArgs("--reset-values"))
return funcs.EnvFuncs(
funcs.HelmRepo(
helm.WithArgs("add"),
helm.WithArgs("crossplane-stable"),
helm.WithArgs("https://charts.crossplane.io/stable"),
),
funcs.HelmUpgrade(opts...),
)
}

// helmOptionsForPriorCrossplane returns the helm install/upgrade options for
// the prior Crossplane version.
func (e *Environment) helmOptionsForPriorCrossplane(namespace, release string) []helm.Option {
opts := []helm.Option{
helm.WithNamespace(namespace),
helm.WithName(release),
helm.WithChart("crossplane-stable/crossplane"),
helm.WithArgs(
"--create-namespace",
"--wait",
),
}
if e.priorCrossplaneVersion != nil && *e.priorCrossplaneVersion != "" {
opts = append(opts, helm.WithArgs("--version", *e.priorCrossplaneVersion))
}
return opts
}

// getSuiteInstallOpts returns the helm install options for the specified
// suite, appending additional specified ones.
func (e *Environment) getSuiteInstallOpts(suite string, extra ...helm.Option) []helm.Option {
Expand Down
55 changes: 55 additions & 0 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,61 @@ func TestCrossplaneLifecycle(t *testing.T) {
funcs.ResourceDeletedWithin(3*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
)).
Feature(),
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.").
WithLabel(LabelArea, LabelAreaLifecycle).
WithLabel(LabelSize, LabelSizeSmall).
WithLabel(config.LabelTestSuite, config.TestSuiteDefault).
// We expect Crossplane to have been uninstalled first
Assess("CrossplaneIsNotInstalled", funcs.AllOf(
funcs.ResourceDeletedWithin(1*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
funcs.ResourcesDeletedWithin(3*time.Minute, crdsDir, "*.yaml"),
)).
Assess("InstallCrossplane", funcs.AllOf(
funcs.AsFeaturesFunc(envfuncs.CreateNamespace(namespace)),
funcs.AsFeaturesFunc(environment.HelmInstallBaseCrossplane()),
funcs.ReadyToTestWithin(1*time.Minute, namespace),
)).
Assess("CreateClaimPrerequisites", funcs.AllOf(
funcs.ApplyResources(FieldManager, manifests, "setup/*.yaml"),
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "setup/*.yaml"),
)).
Assess("XRDIsEstablished",
funcs.ResourcesHaveConditionWithin(1*time.Minute, manifests, "setup/definition.yaml", apiextensionsv1.WatchingComposite())).
Assess("ProviderIsReady",
funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "setup/provider.yaml", pkgv1.Healthy(), pkgv1.Active())).
Assess("CreateClaim", funcs.AllOf(
funcs.ApplyResources(FieldManager, manifests, "claim.yaml"),
funcs.ResourcesCreatedWithin(30*time.Second, manifests, "claim.yaml"),
)).
Assess("ClaimIsAvailable", funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "claim.yaml", xpv1.Available())).
Assess("DowngradeCrossplane", funcs.AllOf(
funcs.AsFeaturesFunc(environment.HelmUpgradePriorCrossplane(namespace, helmReleaseName)),
funcs.ReadyToTestWithin(1*time.Minute, namespace),
)).
Assess("CoreDeploymentIsAvailable", funcs.DeploymentBecomesAvailableWithin(1*time.Minute, namespace, "crossplane")).
Assess("RBACManagerDeploymentIsAvailable", funcs.DeploymentBecomesAvailableWithin(1*time.Minute, namespace, "crossplane-rbac-manager")).
Assess("CoreCRDsAreEstablished", funcs.ResourcesHaveConditionWithin(1*time.Minute, crdsDir, "*.yaml", funcs.CRDInitialNamesAccepted())).
Assess("ClaimIsStillAvailable", funcs.ResourcesHaveConditionWithin(3*time.Minute, manifests, "claim.yaml", xpv1.Available())).
Assess("DeleteClaim", funcs.AllOf(
funcs.DeleteResources(manifests, "claim.yaml"),
funcs.ResourcesDeletedWithin(2*time.Minute, manifests, "claim.yaml"),
)).
WithTeardown("DeletePrerequisites", funcs.ResourcesDeletedAfterListedAreGone(3*time.Minute, manifests, "setup/*.yaml", nopList)).
// Uninstalling the Crossplane Helm chart doesn't remove its CRDs. We
// want to make sure they can be deleted cleanly. If they can't, it's a
// sign something they define might have stuck around.
WithTeardown("DeleteCrossplaneCRDs", funcs.AllOf(
funcs.DeleteResources(crdsDir, "*.yaml"),
funcs.ResourcesDeletedWithin(3*time.Minute, crdsDir, "*.yaml"),
)).
// Uninstalling the Crossplane Helm chart doesn't remove the namespace
// it was installed to either. We want to make sure it can be deleted
// cleanly.
WithTeardown("DeleteCrossplaneNamespace", funcs.AllOf(
funcs.AsFeaturesFunc(envfuncs.DeleteNamespace(namespace)),
funcs.ResourceDeletedWithin(3*time.Minute, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}),
)).
Feature(),
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.").
WithLabel(LabelArea, LabelAreaLifecycle).
WithLabel(LabelSize, LabelSizeSmall).
Expand Down

0 comments on commit 0d806ba

Please sign in to comment.