|
| 1 | +package router |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strings" |
| 6 | + "time" |
| 7 | + |
| 8 | + g "github.com/onsi/ginkgo/v2" |
| 9 | + o "github.com/onsi/gomega" |
| 10 | + |
| 11 | + exutil "github.com/openshift/origin/test/extended/util" |
| 12 | + |
| 13 | + corev1 "k8s.io/api/core/v1" |
| 14 | + apierrors "k8s.io/apimachinery/pkg/api/errors" |
| 15 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 16 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
| 17 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 18 | + "k8s.io/apimachinery/pkg/util/wait" |
| 19 | + "k8s.io/kubernetes/test/e2e/framework" |
| 20 | + "k8s.io/kubernetes/test/e2e/upgrades" |
| 21 | + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 22 | +) |
| 23 | + |
| 24 | +// List of Istio CRDs that should remain OLM-managed after migration |
| 25 | +var istioCRDNames = []string{ |
| 26 | + "wasmplugins.extensions.istio.io", |
| 27 | + "destinationrules.networking.istio.io", |
| 28 | + "envoyfilters.networking.istio.io", |
| 29 | + "gateways.networking.istio.io", |
| 30 | + "proxyconfigs.networking.istio.io", |
| 31 | + "serviceentries.networking.istio.io", |
| 32 | + "sidecars.networking.istio.io", |
| 33 | + "virtualservices.networking.istio.io", |
| 34 | + "workloadentries.networking.istio.io", |
| 35 | + "workloadgroups.networking.istio.io", |
| 36 | + "authorizationpolicies.security.istio.io", |
| 37 | + "peerauthentications.security.istio.io", |
| 38 | + "requestauthentications.security.istio.io", |
| 39 | + "telemetries.telemetry.istio.io", |
| 40 | +} |
| 41 | + |
| 42 | +// GatewayAPIMigrationUpgradeTest verifies that Gateway API resources migrate |
| 43 | +// from OLM-based provisioning to CIO-based provisioning during upgrade |
| 44 | +type GatewayAPIMigrationUpgradeTest struct { |
| 45 | + oc *exutil.CLI |
| 46 | + namespace string |
| 47 | + gatewayName string |
| 48 | + routeName string |
| 49 | + hostname string |
| 50 | +} |
| 51 | + |
| 52 | +func (t *GatewayAPIMigrationUpgradeTest) Name() string { |
| 53 | + return "gateway-api-olm-to-no-olm-migration" |
| 54 | +} |
| 55 | + |
| 56 | +func (t *GatewayAPIMigrationUpgradeTest) DisplayName() string { |
| 57 | + return "[sig-network-edge][Feature:Router][apigroup:gateway.networking.k8s.io] Verify Gateway API migration from OLM to NO-OLM during upgrade" |
| 58 | +} |
| 59 | + |
| 60 | +// Setup creates Gateway and HTTPRoute resources with OLM-based provisioning and tests connectivity |
| 61 | +func (t *GatewayAPIMigrationUpgradeTest) Setup(ctx context.Context, f *framework.Framework) { |
| 62 | + g.By("Setting up Gateway API OLM to NO-OLM migration test") |
| 63 | + |
| 64 | + t.oc = exutil.NewCLIWithFramework(f) |
| 65 | + t.namespace = f.Namespace.Name |
| 66 | + t.gatewayName = "upgrade-test-gateway" |
| 67 | + t.routeName = "test-httproute" |
| 68 | + |
| 69 | + configClient := t.oc.AdminConfigClient() |
| 70 | + |
| 71 | + g.By("Checking if GatewayAPIWithoutOLM feature gate is enabled") |
| 72 | + fgs, err := configClient.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{}) |
| 73 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 74 | + |
| 75 | + for _, fg := range fgs.Status.FeatureGates { |
| 76 | + for _, enabledFG := range fg.Enabled { |
| 77 | + if enabledFG.Name == "GatewayAPIWithoutOLM" { |
| 78 | + g.Skip("Skipping upgrade test - GatewayAPIWithoutOLM is already enabled, this test requires starting from OLM-based provisioning") |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + g.By("Creating default GatewayClass to trigger Gateway API installation") |
| 84 | + gatewayClassName := "openshift-default" |
| 85 | + gatewayClassControllerName := "openshift.io/gateway-controller/v1" |
| 86 | + gatewayClass := buildGatewayClass(gatewayClassName, gatewayClassControllerName) |
| 87 | + _, err = t.oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Create(ctx, gatewayClass, metav1.CreateOptions{}) |
| 88 | + if err != nil && !apierrors.IsAlreadyExists(err) { |
| 89 | + framework.Failf("Failed to create GatewayClass %q: %v", gatewayClassName, err) |
| 90 | + } |
| 91 | + |
| 92 | + g.By("Waiting for GatewayClass to be accepted") |
| 93 | + err = checkGatewayClass(t.oc, gatewayClassName) |
| 94 | + o.Expect(err).NotTo(o.HaveOccurred(), "GatewayClass %q was not accepted", gatewayClassName) |
| 95 | + |
| 96 | + g.By("Getting the default domain") |
| 97 | + defaultIngressDomain, err := getDefaultIngressClusterDomainName(t.oc, time.Minute) |
| 98 | + o.Expect(err).NotTo(o.HaveOccurred(), "Failed to find default domain name") |
| 99 | + customDomain := strings.Replace(defaultIngressDomain, "apps.", "gw-upgrade.", 1) |
| 100 | + t.hostname = "test-upgrade." + customDomain |
| 101 | + |
| 102 | + g.By("Creating Gateway with OLM-based provisioning") |
| 103 | + _, err = createAndCheckGateway(t.oc, t.gatewayName, gatewayClassName, customDomain) |
| 104 | + o.Expect(err).NotTo(o.HaveOccurred(), "Failed to create Gateway") |
| 105 | + |
| 106 | + g.By("Verify the gateway's LoadBalancer service and DNSRecords") |
| 107 | + assertGatewayLoadbalancerReady(t.oc, t.gatewayName, t.gatewayName+"-openshift-default") |
| 108 | + assertDNSRecordStatus(t.oc, t.gatewayName) |
| 109 | + |
| 110 | + g.By("Creating HTTPRoute with backend") |
| 111 | + backendName := "echo-backend-" + t.gatewayName |
| 112 | + createHttpRoute(t.oc.AsAdmin(), t.gatewayName, t.routeName, t.hostname, backendName) |
| 113 | + |
| 114 | + g.By("Waiting for HTTPRoute to be accepted") |
| 115 | + _, err = assertHttpRouteSuccessful(t.oc.AsAdmin(), t.gatewayName, t.routeName) |
| 116 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 117 | + |
| 118 | + g.By("Sleeping for 3 minutes to allow DNS propagation and avoid AWS negative caching") |
| 119 | + time.Sleep(3 * time.Minute) |
| 120 | + |
| 121 | + g.By("Verifying HTTP connectivity before upgrade") |
| 122 | + assertHttpRouteConnection(t.hostname) |
| 123 | + |
| 124 | + g.By("Verifying OLM-based Istio CR exists before upgrade") |
| 125 | + // Check for Istio CR created by OLM (cluster-scoped, will be deleted during migration) |
| 126 | + _, err = t.oc.AsAdmin().Run("get").Args("istio", "openshift-gateway").Output() |
| 127 | + o.Expect(err).NotTo(o.HaveOccurred(), "Istio CR should exist before upgrade (OLM-based)") |
| 128 | + |
| 129 | + // Check for Sail Operator subscription (will NOT be removed during migration) |
| 130 | + _, err = t.oc.AsAdmin().Run("get").Args("subscription", "-n", "openshift-operators", "servicemeshoperator3").Output() |
| 131 | + o.Expect(err).NotTo(o.HaveOccurred(), "Sail Operator subscription should exist before upgrade") |
| 132 | + |
| 133 | + framework.Logf("Gateway and HTTPRoute successfully created with OLM-based provisioning, connectivity verified") |
| 134 | +} |
| 135 | + |
| 136 | +// Test validates that resources continue working during upgrade and migrate to CIO after upgrade |
| 137 | +func (t *GatewayAPIMigrationUpgradeTest) Test(ctx context.Context, f *framework.Framework, done <-chan struct{}, _ upgrades.UpgradeType) { |
| 138 | + g.By("Validating Gateway API resources remain functional during upgrade") |
| 139 | + |
| 140 | + // Validate Gateway still exists and is programmed during upgrade |
| 141 | + gatewayClient := t.oc.AdminGatewayApiClient() |
| 142 | + gw, err := gatewayClient.GatewayV1().Gateways(ingressNamespace).Get(ctx, t.gatewayName, metav1.GetOptions{}) |
| 143 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 144 | + o.Expect(gw).NotTo(o.BeNil()) |
| 145 | + |
| 146 | + // Block until upgrade completes |
| 147 | + g.By("Waiting for upgrade to complete") |
| 148 | + <-done |
| 149 | + |
| 150 | + g.By("Sleeping for a minute to allow CIO to take over Gateway API resources") |
| 151 | + time.Sleep(1 * time.Minute) |
| 152 | + |
| 153 | + g.By("Validating migration from OLM to CIO-based provisioning after upgrade") |
| 154 | + |
| 155 | + // Verify Gateway still exists and is programmed |
| 156 | + gw, err = gatewayClient.GatewayV1().Gateways(ingressNamespace).Get(ctx, t.gatewayName, metav1.GetOptions{}) |
| 157 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 158 | + o.Expect(gw).NotTo(o.BeNil()) |
| 159 | + |
| 160 | + var isProgrammed bool |
| 161 | + for _, condition := range gw.Status.Conditions { |
| 162 | + if condition.Type == string(gatewayv1.GatewayConditionProgrammed) && condition.Status == metav1.ConditionTrue { |
| 163 | + isProgrammed = true |
| 164 | + break |
| 165 | + } |
| 166 | + } |
| 167 | + o.Expect(isProgrammed).To(o.BeTrue(), "Gateway should remain programmed after upgrade") |
| 168 | + |
| 169 | + g.By("Verifying Istiod control plane is running after migration") |
| 170 | + // Check that Istiod deployment exists and pods are running |
| 171 | + deployment, err := t.oc.AdminKubeClient().AppsV1().Deployments(ingressNamespace).Get(ctx, "istiod-openshift-gateway", metav1.GetOptions{}) |
| 172 | + o.Expect(err).NotTo(o.HaveOccurred(), "Istiod deployment should exist after migration") |
| 173 | + |
| 174 | + // Verify at least one istiod pod is running |
| 175 | + err = wait.PollUntilContextTimeout(ctx, 2*time.Second, 2*time.Minute, false, func(ctx context.Context) (bool, error) { |
| 176 | + pods, err := t.oc.AdminKubeClient().CoreV1().Pods(ingressNamespace).List(ctx, metav1.ListOptions{ |
| 177 | + LabelSelector: metav1.FormatLabelSelector(deployment.Spec.Selector), |
| 178 | + }) |
| 179 | + if err != nil { |
| 180 | + return false, nil |
| 181 | + } |
| 182 | + if len(pods.Items) < 1 { |
| 183 | + return false, nil |
| 184 | + } |
| 185 | + for _, pod := range pods.Items { |
| 186 | + if pod.Status.Phase == corev1.PodRunning { |
| 187 | + return true, nil |
| 188 | + } |
| 189 | + } |
| 190 | + return false, nil |
| 191 | + }) |
| 192 | + o.Expect(err).NotTo(o.HaveOccurred(), "At least one Istiod pod should be running after migration") |
| 193 | + |
| 194 | + g.By("Verifying Istio CRDs remain managed by OLM") |
| 195 | + // Istio CRDs were installed by OLM and should remain OLM-managed (not taken over by CIO) |
| 196 | + dynamicClient := t.oc.AdminDynamicClient() |
| 197 | + crdResource := schema.GroupVersionResource{ |
| 198 | + Group: "apiextensions.k8s.io", |
| 199 | + Version: "v1", |
| 200 | + Resource: "customresourcedefinitions", |
| 201 | + } |
| 202 | + |
| 203 | + for _, crdName := range istioCRDNames { |
| 204 | + crd, err := dynamicClient.Resource(crdResource).Get(ctx, crdName, metav1.GetOptions{}) |
| 205 | + o.Expect(err).NotTo(o.HaveOccurred(), "Istio CRD %s should exist after migration", crdName) |
| 206 | + |
| 207 | + // Verify OLM management label (CRDs should remain OLM-managed) |
| 208 | + labels, found, err := unstructured.NestedStringMap(crd.Object, "metadata", "labels") |
| 209 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 210 | + o.Expect(found).To(o.BeTrue()) |
| 211 | + o.Expect(labels).To(o.HaveKeyWithValue("olm.managed", "true"), |
| 212 | + "Istio CRD %s should remain OLM-managed after migration", crdName) |
| 213 | + } |
| 214 | + |
| 215 | + g.By("Verifying CIO has taken ownership via GatewayClass") |
| 216 | + // Check GatewayClass has CIO sail library finalizer |
| 217 | + gwc, err := gatewayClient.GatewayV1().GatewayClasses().Get(ctx, "openshift-default", metav1.GetOptions{}) |
| 218 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 219 | + |
| 220 | + hasCIOFinalizer := false |
| 221 | + expectedFinalizer := "openshift.io/ingress-operator-sail-finalizer" |
| 222 | + for _, finalizer := range gwc.Finalizers { |
| 223 | + if finalizer == expectedFinalizer { |
| 224 | + hasCIOFinalizer = true |
| 225 | + break |
| 226 | + } |
| 227 | + } |
| 228 | + o.Expect(hasCIOFinalizer).To(o.BeTrue(), "GatewayClass should have CIO sail library finalizer after upgrade") |
| 229 | + |
| 230 | + // Check GatewayClass has required CIO conditions |
| 231 | + var hasControllerInstalled, hasCRDsReady bool |
| 232 | + for _, condition := range gwc.Status.Conditions { |
| 233 | + if condition.Type == "ControllerInstalled" && condition.Status == metav1.ConditionTrue { |
| 234 | + hasControllerInstalled = true |
| 235 | + } |
| 236 | + if condition.Type == "CRDsReady" && condition.Status == metav1.ConditionTrue { |
| 237 | + hasCRDsReady = true |
| 238 | + } |
| 239 | + } |
| 240 | + o.Expect(hasControllerInstalled).To(o.BeTrue(), "GatewayClass should have ControllerInstalled condition after upgrade") |
| 241 | + o.Expect(hasCRDsReady).To(o.BeTrue(), "GatewayClass should have CRDsReady condition after upgrade") |
| 242 | + |
| 243 | + g.By("Verifying migration from OLM-based Istio CR to Sail Library") |
| 244 | + // The OLM Subscription for Sail Operator should still exist (it's not removed during migration) |
| 245 | + _, err = t.oc.AsAdmin().Run("get").Args("subscription", "-n", "openshift-operators", "servicemeshoperator3").Output() |
| 246 | + o.Expect(err).NotTo(o.HaveOccurred(), "Sail Operator subscription should still exist after upgrade") |
| 247 | + |
| 248 | + // The Istio CR created by OLM should be deleted by CIO during migration |
| 249 | + _, err = t.oc.AsAdmin().Run("get").Args("istio", "openshift-gateway").Output() |
| 250 | + o.Expect(err).To(o.HaveOccurred(), "Istio CR should be deleted during migration") |
| 251 | + o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(), "Istio CR should return NotFound error") |
| 252 | + |
| 253 | + // IstioRevision should also be cleaned up |
| 254 | + _, err = t.oc.AsAdmin().Run("get").Args("istiorevision", "openshift-gateway").Output() |
| 255 | + o.Expect(err).To(o.HaveOccurred(), "IstioRevision should be cleaned up during migration") |
| 256 | + o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(), "IstioRevision should return NotFound error") |
| 257 | + |
| 258 | + g.By("Verifying HTTPRoute still exists and is accepted after upgrade") |
| 259 | + _, err = assertHttpRouteSuccessful(t.oc.AsAdmin(), t.gatewayName, t.routeName) |
| 260 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 261 | + |
| 262 | + g.By("Verifying HTTP connectivity after upgrade") |
| 263 | + assertHttpRouteConnection(t.hostname) |
| 264 | + |
| 265 | + framework.Logf("Gateway API successfully migrated from Istio CR (OLM) to Sail Library (CIO Helm-based)") |
| 266 | +} |
| 267 | + |
| 268 | +// Teardown cleans up Gateway API resources, Istio CR, and OSSM subscription |
| 269 | +// This runs even if the test fails, ensuring complete cleanup |
| 270 | +func (t *GatewayAPIMigrationUpgradeTest) Teardown(ctx context.Context, f *framework.Framework) { |
| 271 | + g.By("Deleting the Sail Operator subscription") |
| 272 | + subscriptionName := "servicemeshoperator3" |
| 273 | + subscriptionNamespace := "openshift-operators" |
| 274 | + err := t.oc.AsAdmin().Run("delete").Args("--ignore-not-found=true", "subscription", "-n", subscriptionNamespace, subscriptionName).Execute() |
| 275 | + if err != nil { |
| 276 | + framework.Logf("Failed to delete Subscription %q: %v", subscriptionName, err) |
| 277 | + } |
| 278 | + |
| 279 | + g.By("Deleting the Istio CR if it exists") |
| 280 | + // Delete the Istio CR explicitly (may still exist if test failed before migration completed) |
| 281 | + istioName := "openshift-gateway" |
| 282 | + err = t.oc.AsAdmin().Run("delete").Args("--ignore-not-found=true", "istio", istioName).Execute() |
| 283 | + if err != nil { |
| 284 | + framework.Logf("Failed to delete Istio CR %q: %v", istioName, err) |
| 285 | + } |
| 286 | + |
| 287 | + g.By("Deleting the Gateway") |
| 288 | + err = t.oc.AdminGatewayApiClient().GatewayV1().Gateways(ingressNamespace).Delete(ctx, t.gatewayName, metav1.DeleteOptions{}) |
| 289 | + if err != nil && !apierrors.IsNotFound(err) { |
| 290 | + framework.Logf("Failed to delete Gateway %q: %v", t.gatewayName, err) |
| 291 | + } |
| 292 | + |
| 293 | + g.By("Deleting the GatewayClass") |
| 294 | + gatewayClassName := "openshift-default" |
| 295 | + err = t.oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Delete(ctx, gatewayClassName, metav1.DeleteOptions{}) |
| 296 | + if err != nil && !apierrors.IsNotFound(err) { |
| 297 | + framework.Logf("Failed to delete GatewayClass %q: %v", gatewayClassName, err) |
| 298 | + } |
| 299 | + |
| 300 | + g.By("Waiting for istiod pods to be deleted") |
| 301 | + o.Eventually(func(g o.Gomega) { |
| 302 | + podsList, err := t.oc.AdminKubeClient().CoreV1().Pods(ingressNamespace).List(ctx, metav1.ListOptions{ |
| 303 | + LabelSelector: "app=istiod", |
| 304 | + }) |
| 305 | + g.Expect(err).NotTo(o.HaveOccurred()) |
| 306 | + g.Expect(podsList.Items).Should(o.BeEmpty(), "Istiod pods should be deleted") |
| 307 | + }).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(o.Succeed()) |
| 308 | + |
| 309 | + framework.Logf("Gateway API resources, Istio CR, and OSSM subscription successfully cleaned up") |
| 310 | +} |
0 commit comments