Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/extended/router/gatewayapicontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import (
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

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 (
Expand Down Expand Up @@ -59,6 +66,11 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
// skip non clould platforms since gateway needs LB service
skipGatewayIfNonCloudPlatform(oc)

// GatewayAPIController relies on OSSM OLM operator.
// Skipping on clusters which don't have capabilities required
// to install an OLM operator.
exutil.SkipIfMissingCapabilities(oc, requiredCapabilities...)

// create the default gatewayClass
gatewayClass := buildGatewayClass(gatewayClassName, gatewayClassControllerName)
_, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
Expand Down
30 changes: 30 additions & 0 deletions test/extended/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down