diff --git a/test/extended/router/gatewayapicontroller.go b/test/extended/router/gatewayapicontroller.go index 635d7db0de7f..d38bd65f0915 100644 --- a/test/extended/router/gatewayapicontroller.go +++ b/test/extended/router/gatewayapicontroller.go @@ -26,6 +26,13 @@ import ( gatewayapiclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned" ) +var ( + requiredCapabilities = []configv1.ClusterVersionCapability{ + configv1.ClusterVersionCapabilityMarketplace, + configv1.ClusterVersionCapabilityOperatorLifecycleManager, + } +) + var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feature:Router][apigroup:gateway.networking.k8s.io]", g.Ordered, g.Serial, func() { defer g.GinkgoRecover() var ( @@ -73,6 +80,11 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat g.Skip(fmt.Sprintf("Skipping on non cloud platform type %q", platformType)) } + // GatewayAPIController relies on OSSM OLM operator. + // Skipping on clusters which don't have capabilities required + // to install an OLM operator. + exutil.SkipIfMissingCapabilities(oc, requiredCapabilities...) + gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig()) // create the default gatewayClass gatewayClass := buildGatewayClass(gatewayClassName, gatewayClassControllerName) @@ -80,7 +92,6 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat if err != nil && !apierrors.IsAlreadyExists(err) { e2e.Failf("Failed to create GatewayClass %q", gatewayClassName) } - }) g.AfterAll(func() { diff --git a/test/extended/util/framework.go b/test/extended/util/framework.go index cf6bbf4af1e6..fab0d1002d8e 100644 --- a/test/extended/util/framework.go +++ b/test/extended/util/framework.go @@ -2404,6 +2404,27 @@ func IsCapabilityEnabled(oc *CLI, cap configv1.ClusterVersionCapability) (bool, return false, nil } +// AllCapabilitiesEnabled returns true if all of the given capabilities are enabled on the cluster. +func AllCapabilitiesEnabled(oc *CLI, caps ...configv1.ClusterVersionCapability) (bool, error) { + cv, err := oc.AdminConfigClient().ConfigV1().ClusterVersions().Get(context.Background(), "version", metav1.GetOptions{}) + if err != nil { + return false, err + } + + enabledCaps := make(map[configv1.ClusterVersionCapability]struct{}, len(cv.Status.Capabilities.EnabledCapabilities)) + for _, c := range cv.Status.Capabilities.EnabledCapabilities { + enabledCaps[c] = struct{}{} + } + + for _, c := range caps { + if _, found := enabledCaps[c]; !found { + return false, nil + } + } + + return true, nil +} + // SkipIfNotPlatform skip the test if supported platforms are not matched func SkipIfNotPlatform(oc *CLI, platforms ...configv1.PlatformType) { var match bool @@ -2420,6 +2441,15 @@ func SkipIfNotPlatform(oc *CLI, platforms ...configv1.PlatformType) { } } +// SkipIfMissingCapabilities skips the test if any of the given cluster capabilities is not enabled. +func SkipIfMissingCapabilities(oc *CLI, caps ...configv1.ClusterVersionCapability) { + enabled, err := AllCapabilitiesEnabled(oc, caps...) + o.Expect(err).NotTo(o.HaveOccurred()) + if !enabled { + g.Skip(fmt.Sprintf("Skip this test scenario because not all of the following capabilities are enabled: %v", caps)) + } +} + // GetClusterRegion get the cluster's region func GetClusterRegion(oc *CLI) string { region, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("node", `-ojsonpath={.items[].metadata.labels.topology\.kubernetes\.io/region}`).Output()