@@ -19,9 +19,12 @@ import (
1919
2020 "github.com/onsi/ginkgo/v2"
2121 configv1 "github.com/openshift/api/config/v1"
22+ clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned"
23+ "github.com/pkg/errors"
2224 "github.com/sirupsen/logrus"
2325 "github.com/spf13/pflag"
2426 "golang.org/x/mod/semver"
27+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2528 "k8s.io/apimachinery/pkg/util/sets"
2629 "k8s.io/cli-runtime/pkg/genericclioptions"
2730 "k8s.io/client-go/discovery"
@@ -30,6 +33,7 @@ import (
3033
3134 "github.com/openshift/origin/pkg/clioptions/clusterdiscovery"
3235 "github.com/openshift/origin/pkg/clioptions/clusterinfo"
36+ "github.com/openshift/origin/pkg/clioptions/kubeconfig"
3337 "github.com/openshift/origin/pkg/defaultmonitortests"
3438 "github.com/openshift/origin/pkg/monitor"
3539 monitorserialization "github.com/openshift/origin/pkg/monitor/serialization"
@@ -192,11 +196,11 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, junitSuiteName string, mon
192196 listContext , listContextCancel := context .WithTimeout (context .Background (), 10 * time .Minute )
193197 defer listContextCancel ()
194198
195- envFlags , err := determineEnvironmentFlags (upgrade , o .DryRun )
199+ envFlags , err := determineEnvironmentFlags (ctx , upgrade , o .DryRun )
196200 if err != nil {
197201 return fmt .Errorf ("could not determine environment flags: %w" , err )
198202 }
199- logrus .WithField ( "flags" , envFlags .String ()).Infof ("Determined all potential environment flags" )
203+ logrus .WithFields ( envFlags .LogFields ()).Infof ("Determined all potential environment flags" )
200204
201205 externalTestSpecs , err := externalBinaries .ListTests (listContext , defaultBinaryParallelism , envFlags )
202206 if err != nil {
@@ -753,13 +757,13 @@ outerLoop:
753757 return matches , nil
754758}
755759
756- func determineEnvironmentFlags (upgrade bool , dryRun bool ) (extensions.EnvironmentFlags , error ) {
757- clientConfig , err := e2e .LoadConfig (true )
760+ func determineEnvironmentFlags (ctx context. Context , upgrade bool , dryRun bool ) (extensions.EnvironmentFlags , error ) {
761+ restConfig , err := e2e .LoadConfig (true )
758762 if err != nil {
759763 logrus .WithError (err ).Error ("error calling e2e.LoadConfig" )
760764 return nil , err
761765 }
762- clusterState , err := clusterdiscovery .DiscoverClusterState (clientConfig )
766+ clusterState , err := clusterdiscovery .DiscoverClusterState (restConfig )
763767 if err != nil {
764768 logrus .WithError (err ).Warn ("error Discovering Cluster State, flags requiring it will not be present" )
765769 }
@@ -780,6 +784,29 @@ func determineEnvironmentFlags(upgrade bool, dryRun bool) (extensions.Environmen
780784 AddNetworkStack (config .IPFamily ).
781785 AddExternalConnectivity (determineExternalConnectivity (config ))
782786
787+ clientConfig , err := clientconfigv1 .NewForConfig (restConfig )
788+ if err != nil {
789+ return nil , err
790+ }
791+
792+ discoveryClient , err := kubeconfig .NewDiscoveryGetter (restConfig ).GetDiscoveryClient ()
793+ if err != nil {
794+ return nil , err
795+ }
796+ apiGroups , err := determineEnabledAPIGroups (discoveryClient )
797+ if err != nil {
798+ return nil , errors .WithMessage (err , "couldn't determine api groups" )
799+ }
800+ envFlagBuilder .AddAPIGroups (apiGroups .UnsortedList ()... )
801+
802+ if apiGroups .Has ("config.openshift.io" ) {
803+ featureGates , err := determineEnabledFeatureGates (ctx , clientConfig )
804+ if err != nil {
805+ return nil , errors .WithMessage (err , "couldn't determine feature gates" )
806+ }
807+ envFlagBuilder .AddFeatureGates (featureGates ... )
808+ }
809+
783810 //Additional flags can only be determined if we are able to obtain the clusterState
784811 if clusterState != nil {
785812 upgradeType := "None"
@@ -836,3 +863,55 @@ func determineExternalConnectivity(clusterConfig *clusterdiscovery.ClusterConfig
836863 }
837864 return "Direct"
838865}
866+
867+ func determineEnabledAPIGroups (discoveryClient discovery.AggregatedDiscoveryInterface ) (sets.Set [string ], error ) {
868+ groups , err := discoveryClient .ServerGroups ()
869+ if err != nil {
870+ return nil , fmt .Errorf ("unable to retrieve served resources: %v" , err )
871+ }
872+ apiGroups := sets .New [string ]()
873+ for _ , apiGroup := range groups .Groups {
874+ // ignore the empty group
875+ if apiGroup .Name == "" {
876+ continue
877+ }
878+ apiGroups .Insert (apiGroup .Name )
879+ }
880+
881+ return apiGroups , nil
882+ }
883+
884+ func determineEnabledFeatureGates (ctx context.Context , configClient clientconfigv1.Interface ) ([]string , error ) {
885+ featureGate , err := configClient .ConfigV1 ().FeatureGates ().Get (ctx , "cluster" , metav1.GetOptions {})
886+ if err != nil {
887+ return nil , err
888+ }
889+ clusterVersion , err := configClient .ConfigV1 ().ClusterVersions ().Get (ctx , "version" , metav1.GetOptions {})
890+ if err != nil {
891+ return nil , err
892+ }
893+
894+ desiredVersion := clusterVersion .Status .Desired .Version
895+ if len (desiredVersion ) == 0 && len (clusterVersion .Status .History ) > 0 {
896+ desiredVersion = clusterVersion .Status .History [0 ].Version
897+ }
898+
899+ ret := sets .NewString ()
900+ found := false
901+ for _ , featureGateValues := range featureGate .Status .FeatureGates {
902+ if featureGateValues .Version != desiredVersion {
903+ continue
904+ }
905+ found = true
906+ for _ , enabled := range featureGateValues .Enabled {
907+ ret .Insert (string (enabled .Name ))
908+ }
909+ break
910+ }
911+ if ! found {
912+ logrus .Warning ("no feature gates found" )
913+ return nil , nil
914+ }
915+
916+ return ret .List (), nil
917+ }
0 commit comments