@@ -19,9 +19,12 @@ import (
19
19
20
20
"github.com/onsi/ginkgo/v2"
21
21
configv1 "github.com/openshift/api/config/v1"
22
+ clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned"
23
+ "github.com/pkg/errors"
22
24
"github.com/sirupsen/logrus"
23
25
"github.com/spf13/pflag"
24
26
"golang.org/x/mod/semver"
27
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
28
"k8s.io/apimachinery/pkg/util/sets"
26
29
"k8s.io/cli-runtime/pkg/genericclioptions"
27
30
"k8s.io/client-go/discovery"
@@ -30,6 +33,7 @@ import (
30
33
31
34
"github.com/openshift/origin/pkg/clioptions/clusterdiscovery"
32
35
"github.com/openshift/origin/pkg/clioptions/clusterinfo"
36
+ "github.com/openshift/origin/pkg/clioptions/kubeconfig"
33
37
"github.com/openshift/origin/pkg/defaultmonitortests"
34
38
"github.com/openshift/origin/pkg/monitor"
35
39
monitorserialization "github.com/openshift/origin/pkg/monitor/serialization"
@@ -192,11 +196,11 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, junitSuiteName string, mon
192
196
listContext , listContextCancel := context .WithTimeout (context .Background (), 10 * time .Minute )
193
197
defer listContextCancel ()
194
198
195
- envFlags , err := determineEnvironmentFlags (upgrade , o .DryRun )
199
+ envFlags , err := determineEnvironmentFlags (ctx , upgrade , o .DryRun )
196
200
if err != nil {
197
201
return fmt .Errorf ("could not determine environment flags: %w" , err )
198
202
}
199
- logrus .WithField ( "flags" , envFlags .String ()).Infof ("Determined all potential environment flags" )
203
+ logrus .WithFields ( envFlags .LogFields ()).Infof ("Determined all potential environment flags" )
200
204
201
205
externalTestSpecs , err := externalBinaries .ListTests (listContext , defaultBinaryParallelism , envFlags )
202
206
if err != nil {
@@ -753,13 +757,13 @@ outerLoop:
753
757
return matches , nil
754
758
}
755
759
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 )
758
762
if err != nil {
759
763
logrus .WithError (err ).Error ("error calling e2e.LoadConfig" )
760
764
return nil , err
761
765
}
762
- clusterState , err := clusterdiscovery .DiscoverClusterState (clientConfig )
766
+ clusterState , err := clusterdiscovery .DiscoverClusterState (restConfig )
763
767
if err != nil {
764
768
logrus .WithError (err ).Warn ("error Discovering Cluster State, flags requiring it will not be present" )
765
769
}
@@ -780,6 +784,27 @@ func determineEnvironmentFlags(upgrade bool, dryRun bool) (extensions.Environmen
780
784
AddNetworkStack (config .IPFamily ).
781
785
AddExternalConnectivity (determineExternalConnectivity (config ))
782
786
787
+ clientConfig , err := clientconfigv1 .NewForConfig (restConfig )
788
+ if err != nil {
789
+ return nil , err
790
+ }
791
+
792
+ featureGates , err := determineEnabledFeatureGates (ctx , clientConfig )
793
+ if err != nil {
794
+ return nil , errors .WithMessage (err , "couldn't determine feature gates" )
795
+ }
796
+ envFlagBuilder .AddFeatureGates (featureGates ... )
797
+
798
+ discoveryClient , err := kubeconfig .NewDiscoveryGetter (restConfig ).GetDiscoveryClient ()
799
+ if err != nil {
800
+ return nil , err
801
+ }
802
+ apiGroups , err := determineEnabledAPIGroups (discoveryClient )
803
+ if err != nil {
804
+ return nil , errors .WithMessage (err , "couldn't determine api groups" )
805
+ }
806
+ envFlagBuilder .AddAPIGroups (apiGroups ... )
807
+
783
808
//Additional flags can only be determined if we are able to obtain the clusterState
784
809
if clusterState != nil {
785
810
upgradeType := "None"
@@ -836,3 +861,55 @@ func determineExternalConnectivity(clusterConfig *clusterdiscovery.ClusterConfig
836
861
}
837
862
return "Direct"
838
863
}
864
+
865
+ func determineEnabledAPIGroups (discoveryClient discovery.AggregatedDiscoveryInterface ) ([]string , error ) {
866
+ groups , err := discoveryClient .ServerGroups ()
867
+ if err != nil {
868
+ return nil , fmt .Errorf ("unable to retrieve served resources: %v" , err )
869
+ }
870
+ apiGroups := sets .NewString ()
871
+ for _ , apiGroup := range groups .Groups {
872
+ // ignore the empty group
873
+ if apiGroup .Name == "" {
874
+ continue
875
+ }
876
+ apiGroups .Insert (apiGroup .Name )
877
+ }
878
+
879
+ return apiGroups .List (), nil
880
+ }
881
+
882
+ func determineEnabledFeatureGates (ctx context.Context , configClient clientconfigv1.Interface ) ([]string , error ) {
883
+ featureGate , err := configClient .ConfigV1 ().FeatureGates ().Get (ctx , "cluster" , metav1.GetOptions {})
884
+ if err != nil {
885
+ return nil , err
886
+ }
887
+ clusterVersion , err := configClient .ConfigV1 ().ClusterVersions ().Get (ctx , "version" , metav1.GetOptions {})
888
+ if err != nil {
889
+ return nil , err
890
+ }
891
+
892
+ desiredVersion := clusterVersion .Status .Desired .Version
893
+ if len (desiredVersion ) == 0 && len (clusterVersion .Status .History ) > 0 {
894
+ desiredVersion = clusterVersion .Status .History [0 ].Version
895
+ }
896
+
897
+ ret := sets .NewString ()
898
+ found := false
899
+ for _ , featureGateValues := range featureGate .Status .FeatureGates {
900
+ if featureGateValues .Version != desiredVersion {
901
+ continue
902
+ }
903
+ found = true
904
+ for _ , enabled := range featureGateValues .Enabled {
905
+ ret .Insert (string (enabled .Name ))
906
+ }
907
+ break
908
+ }
909
+ if ! found {
910
+ logrus .Warning ("no feature gates found" )
911
+ return nil , nil
912
+ }
913
+
914
+ return ret .List (), nil
915
+ }
0 commit comments