@@ -19,6 +19,7 @@ import (
1919 machinev1beta1 "github.com/openshift/api/machine/v1beta1"
2020 mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
2121 opv1 "github.com/openshift/api/operator/v1"
22+ configv1client "github.com/openshift/client-go/config/clientset/versioned"
2223 machineclient "github.com/openshift/client-go/machine/clientset/versioned"
2324 machineconfigclient "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
2425 mcopclient "github.com/openshift/client-go/operator/clientset/versioned"
@@ -149,6 +150,34 @@ func skipOnMetal(oc *exutil.CLI) {
149150 }
150151}
151152
153+ // `isFeatureGateEnabled` checks if the desired feature gate provided as a parameter is enabled in
154+ // the test cluster. It returns true if the feature gate is enabled and false otherwise.
155+ func isFeatureGateEnabled (configClient configv1client.Interface , featureGate osconfigv1.FeatureGateName ) bool {
156+ // Get the FeatureGates resource
157+ fgs , err := configClient .ConfigV1 ().FeatureGates ().Get (context .TODO (), "cluster" , metav1.GetOptions {})
158+ o .Expect (err ).NotTo (o .HaveOccurred (), "Error getting clsuter FeatureGates." )
159+
160+ // Loop through the feature gates to see if the desired one is enabled
161+ fgEnabled := false
162+ for _ , fg := range fgs .Status .FeatureGates {
163+ for _ , enabledFG := range fg .Enabled {
164+ if enabledFG .Name == featureGate {
165+ fgEnabled = true
166+ break
167+ }
168+ }
169+ }
170+ return fgEnabled
171+ }
172+
173+ // `SkipWhenFeatureGateEnabled` skips a test if the desired feature gate provided as a parameter is
174+ // enabled in the test cluster.
175+ func SkipWhenFeatureGateEnabled (configClient configv1client.Interface , featureGate osconfigv1.FeatureGateName ) {
176+ if isFeatureGateEnabled (configClient , featureGate ) {
177+ e2eskipper .Skipf ("Skipping this test since the `%v` FeatureGate is enabled." , featureGate )
178+ }
179+ }
180+
152181// `GetRolesToTest` gets the MCPs in a cluster with nodes associated to it. This allows a more robust way to determine
153182// the roles to use when selecting nodes and testing their MCP associations in an MCN.
154183func GetRolesToTest (oc * exutil.CLI , machineConfigClient * machineconfigclient.Clientset ) []string {
0 commit comments