|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +package e2e |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + "k8s.io/apimachinery/pkg/api/errors" |
| 12 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 13 | + "k8s.io/apimachinery/pkg/types" |
| 14 | + "k8s.io/apimachinery/pkg/util/wait" |
| 15 | + gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 16 | + |
| 17 | + configv1 "github.com/openshift/api/config/v1" |
| 18 | + "github.com/openshift/api/features" |
| 19 | +) |
| 20 | + |
| 21 | +// TestOSSMOperatorUpgradeViaIntermediateVersions verifies that the OSSM operator |
| 22 | +// correctly upgrades through intermediate versions. It ensures the upgrade logic automatically approves |
| 23 | +// each InstallPlan along the upgrade graph until the desired version is reached. |
| 24 | +// This test upgrades from version 3.0.0 to 3.0.2, validating that it passes through |
| 25 | +// the known intermediate version 3.0.1. Starting from the default (== hard coded) version |
| 26 | +// is not feasible as future upgrade paths cannot be predetermined. |
| 27 | +func TestOSSMOperatorUpgradeViaIntermediateVersions(t *testing.T) { |
| 28 | + gatewayAPIEnabled, err := isFeatureGateEnabled(features.FeatureGateGatewayAPI) |
| 29 | + if err != nil { |
| 30 | + t.Fatalf("Error checking feature gate enabled status: %v", err) |
| 31 | + } |
| 32 | + |
| 33 | + gatewayAPIControllerEnabled, err := isFeatureGateEnabled(features.FeatureGateGatewayAPIController) |
| 34 | + if err != nil { |
| 35 | + t.Fatalf("Error checking controller feature gate enabled status: %v", err) |
| 36 | + } |
| 37 | + |
| 38 | + if !gatewayAPIEnabled || !gatewayAPIControllerEnabled { |
| 39 | + t.Skip("Gateway API featuregates are not enabled, skipping TestOSSMOperatorUpgradeViaIntermediateVersions") |
| 40 | + } |
| 41 | + |
| 42 | + // Delete GatewayClass and uninstall OSSM operator at the end of the test. |
| 43 | + t.Cleanup(func() { |
| 44 | + gc := &gatewayapiv1.GatewayClass{ObjectMeta: metav1.ObjectMeta{Name: "openshift-default"}} |
| 45 | + if err := kclient.Delete(context.TODO(), gc); err != nil { |
| 46 | + if errors.IsNotFound(err) { |
| 47 | + return |
| 48 | + } |
| 49 | + t.Errorf("Failed to delete gatewayclass %q: %v", gc.Name, err) |
| 50 | + } |
| 51 | + // TODO: Uninstall OSSM after test is completed. |
| 52 | + }) |
| 53 | + |
| 54 | + var ( |
| 55 | + initialOSSMVersion = "servicemeshoperator3.v3.0.0" |
| 56 | + upgradeOSSMVersion = "servicemeshoperator3.v3.0.2" |
| 57 | + ) |
| 58 | + |
| 59 | + // Set OSSM version to 3.0.0. |
| 60 | + t.Logf("Creating GatewayClass with OSSMversion %q...", initialOSSMVersion) |
| 61 | + gatewayClass := buildGatewayClass("openshift-default", "openshift.io/gateway-controller/v1") |
| 62 | + if gatewayClass.Annotations == nil { |
| 63 | + gatewayClass.Annotations = map[string]string{} |
| 64 | + } |
| 65 | + gatewayClass.Annotations["unsupported.do-not-use.openshift.io/ossm-version"] = initialOSSMVersion |
| 66 | + gatewayClass.Annotations["unsupported.do-not-use.openshift.io/istio-version"] = "v1.24.3" |
| 67 | + if err := kclient.Create(context.TODO(), gatewayClass); err != nil { |
| 68 | + t.Fatalf("Failed to create gatewayclass %s: %v", gatewayClass.Name, err) |
| 69 | + } |
| 70 | + t.Log("Checking for the Subscription...") |
| 71 | + if err := assertSubscription(t, openshiftOperatorsNamespace, expectedSubscriptionName); err != nil { |
| 72 | + t.Fatalf("Failed to find expected Subscription %s: %v", expectedSubscriptionName, err) |
| 73 | + } |
| 74 | + t.Log("Checking for the CatalogSource...") |
| 75 | + if err := assertCatalogSource(t, expectedCatalogSourceNamespace, expectedCatalogSourceName); err != nil { |
| 76 | + t.Fatalf("Failed to find expected CatalogSource %s: %v", expectedCatalogSourceName, err) |
| 77 | + } |
| 78 | + t.Log("Checking for the OSSM operator deployment...") |
| 79 | + if err := assertOSSMOperatorWithConfig(t, initialOSSMVersion, 2*time.Second, 60*time.Second); err != nil { |
| 80 | + t.Fatalf("Failed to find expected Istio operator: %v", err) |
| 81 | + } |
| 82 | + t.Log("Checking for the Istio CR...") |
| 83 | + if err := assertIstio(t); err != nil { |
| 84 | + t.Fatalf("Failed to find expected Istio: %v", err) |
| 85 | + } |
| 86 | + t.Log("Checking for the Istiod deployment...") |
| 87 | + if err := assertIstiodControlPlane(t); err != nil { |
| 88 | + t.Fatalf("Failed to find expected Istiod control plane: %v", err) |
| 89 | + } |
| 90 | + t.Log("Checking for the GatewayClass readiness...") |
| 91 | + if _, err := assertGatewayClassSuccessful(t, "openshift-default"); err != nil { |
| 92 | + t.Fatalf("Failed to find successful GatewayClass: %v", err) |
| 93 | + } |
| 94 | + |
| 95 | + // Set OSSM version to 3.0.2 |
| 96 | + t.Logf("Updating GatewayClass to version %q...", upgradeOSSMVersion) |
| 97 | + if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 30*time.Second, false, func(context context.Context) (bool, error) { |
| 98 | + gc := &gatewayapiv1.GatewayClass{} |
| 99 | + if err := kclient.Get(context, types.NamespacedName{Name: gatewayClass.Name}, gc); err != nil { |
| 100 | + t.Logf("Failed to get GatewayClass %q: %v, retrying...", gatewayClass.Name, err) |
| 101 | + return false, nil |
| 102 | + } |
| 103 | + if gc.Annotations == nil { |
| 104 | + gc.Annotations = map[string]string{} |
| 105 | + } |
| 106 | + gc.Annotations["unsupported.do-not-use.openshift.io/ossm-version"] = upgradeOSSMVersion |
| 107 | + if err := kclient.Update(context, gc); err != nil { |
| 108 | + t.Logf("Failed to update GatewayClass %q: %v, retrying...", gc.Name, err) |
| 109 | + return false, nil |
| 110 | + } |
| 111 | + t.Logf("GatewayClass %q has been updated to version %q", gc.Name, upgradeOSSMVersion) |
| 112 | + return true, nil |
| 113 | + }); err != nil { |
| 114 | + t.Fatalf("Failed to update GatewayClass to next version: %v", err) |
| 115 | + } |
| 116 | + t.Log("Checking for the status...") |
| 117 | + expectedProgressing := configv1.ClusterOperatorStatusCondition{ |
| 118 | + Type: configv1.OperatorProgressing, |
| 119 | + Status: configv1.ConditionTrue, |
| 120 | + Reason: "OSSMOperatorUpgrading", |
| 121 | + } |
| 122 | + if err := waitForClusterOperatorConditions(t, kclient, expectedProgressing); err != nil { |
| 123 | + t.Fatalf("Operator should be Progressing=True while upgrading: %v", err) |
| 124 | + } |
| 125 | + t.Log("Checking for the OSSM operator deployment...") |
| 126 | + if err := assertOSSMOperatorWithConfig(t, upgradeOSSMVersion, 2*time.Second, 2*time.Minute); err != nil { |
| 127 | + t.Fatalf("failed to find expected Istio operator: %v", err) |
| 128 | + } |
| 129 | + t.Log("Re-checking for the status...") |
| 130 | + expectedProgressing = configv1.ClusterOperatorStatusCondition{ |
| 131 | + Type: configv1.OperatorProgressing, |
| 132 | + Status: configv1.ConditionFalse, |
| 133 | + Reason: "AsExpectedAndOSSMOperatorUpToDate", |
| 134 | + } |
| 135 | + if err := waitForClusterOperatorConditions(t, kclient, expectedProgressing); err != nil { |
| 136 | + t.Fatalf("Operator should be Progressing=False once upgrade reached desired version: %v", err) |
| 137 | + } |
| 138 | + t.Log("Checking for the GatewayClass readiness...") |
| 139 | + if _, err := assertGatewayClassSuccessful(t, "openshift-default"); err != nil { |
| 140 | + t.Fatalf("Failed to find successful GatewayClass: %v", err) |
| 141 | + } |
| 142 | +} |
0 commit comments