From 99443b0b990f02f44685e44c9c7955a45cd2ec1a Mon Sep 17 00:00:00 2001 From: Hasan Turken Date: Thu, 5 Dec 2024 09:20:39 +0300 Subject: [PATCH] e2e: cover downgrades in the lifecycle test case Signed-off-by: Hasan Turken --- test/e2e/config/environment.go | 48 ++++++++++++++++++++++------- test/e2e/install_test.go | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 11 deletions(-) diff --git a/test/e2e/config/environment.go b/test/e2e/config/environment.go index 931d503fabd..488d65595d8 100644 --- a/test/e2e/config/environment.go +++ b/test/e2e/config/environment.go @@ -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 { diff --git a/test/e2e/install_test.go b/test/e2e/install_test.go index 2e650492c49..dd4fd41e23c 100644 --- a/test/e2e/install_test.go +++ b/test/e2e/install_test.go @@ -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).