From 122e267c1a857b2b7875b2727a4da38d45dc6b94 Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Fri, 14 Jun 2024 11:24:03 +0100 Subject: [PATCH] Add test to ensure that dropped operand versions can be upgraded with latest Operator --- test/e2e/upgrade/dropped_operand_test.go | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 test/e2e/upgrade/dropped_operand_test.go diff --git a/test/e2e/upgrade/dropped_operand_test.go b/test/e2e/upgrade/dropped_operand_test.go new file mode 100644 index 000000000..a825ea4dc --- /dev/null +++ b/test/e2e/upgrade/dropped_operand_test.go @@ -0,0 +1,92 @@ +package upgrade + +import ( + "fmt" + "testing" + + ispnv1 "github.com/infinispan/infinispan-operator/api/v1" + "github.com/infinispan/infinispan-operator/controllers/constants" + tutils "github.com/infinispan/infinispan-operator/test/e2e/utils" + coreos "github.com/operator-framework/api/pkg/operators/v1alpha1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestUpgradeFromDroppedOperand(t *testing.T) { + olm := testKube.OLMTestEnv() + olm.PrintManifest() + sourceChannel := olm.SourceChannel + targetChannel := olm.TargetChannel + + testKube.NewNamespace(tutils.Namespace) + sub := &coreos.Subscription{ + TypeMeta: metav1.TypeMeta{ + APIVersion: coreos.SubscriptionCRDAPIVersion, + Kind: coreos.SubscriptionKind, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: olm.SubName, + Namespace: olm.SubNamespace, + }, + Spec: &coreos.SubscriptionSpec{ + Channel: olm.SourceChannel.Name, + CatalogSource: olm.CatalogSource, + CatalogSourceNamespace: olm.CatalogSourceNamespace, + InstallPlanApproval: coreos.ApprovalManual, + Package: olm.SubPackage, + StartingCSV: olm.SubStartingCSV, + Config: coreos.SubscriptionConfig{ + Env: []corev1.EnvVar{ + {Name: "THREAD_DUMP_PRE_STOP", Value: "TRUE"}, + }, + }, + }, + } + defer testKube.CleanupOLMTest(t, tutils.TestName(t), olm.SubName, olm.SubNamespace, olm.SubPackage) + testKube.CreateSubscriptionAndApproveInitialVersion(olm, sub) + + replicas := 1 + spec := tutils.DefaultSpec(t, testKube, func(i *ispnv1.Infinispan) { + i.Spec.Replicas = int32(replicas) + i.Spec.Version = constants.GetEnvWithDefault("TESTING_DROPPED_OPERAND_VERSION", "13.0.10") + }) + testKube.CreateInfinispan(spec, tutils.Namespace) + testKube.WaitForInfinispanPods(replicas, tutils.SinglePodTimeout, spec.Name, tutils.Namespace) + ispn := testKube.WaitForInfinispanConditionWithTimeout(spec.Name, spec.Namespace, ispnv1.ConditionWellFormed, conditionTimeout) + + // Upgrade the Subscription channel if required + if sourceChannel != targetChannel { + testKube.UpdateSubscriptionChannel(targetChannel.Name, sub) + } + + for testKube.Subscription(sub); sub.Status.InstalledCSV != targetChannel.CurrentCSVName; { + testKube.WaitForSubscriptionState(coreos.SubscriptionStateUpgradePending, sub) + testKube.ApproveInstallPlan(sub) + testKube.WaitForSubscription(sub, func() bool { + return sub.Status.InstalledCSV == sub.Status.CurrentCSV + }) + testKube.WaitForCSVSucceeded(sub) + } + + versionManager := testKube.VersionManagerFromCSV(sub) + latestOperand := versionManager.Latest() + tutils.ExpectNoError( + testKube.UpdateInfinispan(ispn, func() { + ispn.Spec.Version = latestOperand.Ref() + fmt.Printf("Upgrading Operand to %s\n", ispn.Spec.Version) + }), + ) + testKube.WaitForInfinispanState(spec.Name, spec.Namespace, func(i *ispnv1.Infinispan) bool { + return !i.IsConditionTrue(ispnv1.ConditionWellFormed) && + i.Status.Operand.Version == latestOperand.Ref() && + i.Status.Operand.Image == latestOperand.Image && + i.Status.Operand.Phase == ispnv1.OperandPhasePending + }) + testKube.WaitForInfinispanPods(replicas, tutils.SinglePodTimeout, spec.Name, tutils.Namespace) + testKube.WaitForInfinispanState(spec.Name, spec.Namespace, func(i *ispnv1.Infinispan) bool { + return i.IsConditionTrue(ispnv1.ConditionWellFormed) && + i.Status.Operand.Version == latestOperand.Ref() && + i.Status.Operand.Image == latestOperand.Image && + i.Status.Operand.Phase == ispnv1.OperandPhaseRunning + }) +}