@@ -21,12 +21,16 @@ import (
2121 "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
2222 "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
2323 configv1 "github.com/openshift/api/config/v1"
24+ "github.com/openshift/origin/pkg/dataloader"
2425 "github.com/pkg/errors"
2526 "github.com/sirupsen/logrus"
2627 "github.com/spf13/pflag"
2728 "golang.org/x/mod/semver"
29+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2830 "k8s.io/apimachinery/pkg/util/sets"
2931 "k8s.io/cli-runtime/pkg/genericclioptions"
32+ "k8s.io/client-go/kubernetes"
33+ "k8s.io/client-go/rest"
3034 e2e "k8s.io/kubernetes/test/e2e/framework"
3135
3236 "github.com/openshift/origin/pkg/clioptions/clusterdiscovery"
@@ -302,7 +306,8 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
302306 // this ensures the tests are always run in random order to avoid
303307 // any intra-tests dependencies
304308 suiteConfig , _ := ginkgo .GinkgoConfiguration ()
305- r := rand .New (rand .NewSource (suiteConfig .RandomSeed ))
309+ randSeed := suiteConfig .RandomSeed
310+ r := rand .New (rand .NewSource (randSeed ))
306311 r .Shuffle (len (tests ), func (i , j int ) { tests [i ], tests [j ] = tests [j ], tests [i ] })
307312
308313 count := o .Count
@@ -351,10 +356,19 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
351356 if parallelism == 0 {
352357 parallelism = suite .Parallelism
353358 }
359+
354360 if parallelism == 0 {
355361 parallelism = 10
356362 }
357363
364+ // adjust based on the number of workers
365+ totalNodes , workerNodes , err := getClusterNodeCounts (ctx , restConfig )
366+ if err != nil {
367+ logrus .Errorf ("Failed to get cluster node counts: %v" , err )
368+ }
369+
370+ logrus .Infof ("Total nodes: %d, Worker nodes: %d, Parallelism: %d" , totalNodes , workerNodes , parallelism )
371+
358372 ctx , cancelFn := context .WithCancel (context .Background ())
359373 defer cancelFn ()
360374 abortCh := make (chan os.Signal , 2 )
@@ -748,6 +762,8 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
748762 if err := riskanalysis .WriteJobRunTestFailureSummary (o .JUnitDir , timeSuffix , finalSuiteResults , wasMasterNodeUpdated , "" ); err != nil {
749763 fmt .Fprintf (o .Out , "error: Unable to write e2e job run failures summary: %v" , err )
750764 }
765+
766+ writeRunSuiteOptions (randSeed , totalNodes , workerNodes , parallelism , monitorTestInfo , o .JUnitDir , timeSuffix )
751767 }
752768
753769 switch {
@@ -779,6 +795,25 @@ func isBlockingFailure(test *testCase) bool {
779795 }
780796}
781797
798+ func writeRunSuiteOptions (seed int64 , totalNodes , workerNodes , parallelism int , info monitortestframework.MonitorTestInitializationInfo , artifactDir , timeSuffix string ) {
799+ var rows []map [string ]string
800+
801+ rows = make ([]map [string ]string , 0 )
802+ rows = append (rows , map [string ]string {"RandomSeed" : fmt .Sprintf ("%d" , seed ), "ClusterStability" : string (info .ClusterStabilityDuringTest ),
803+ "WorkerNodes" : fmt .Sprintf ("%d" , workerNodes ), "TotalNodes" : fmt .Sprintf ("%d" , totalNodes ), "Parallelism" : fmt .Sprintf ("%d" , parallelism )})
804+ dataFile := dataloader.DataFile {
805+ TableName : "run_suite_options" ,
806+ Schema : map [string ]dataloader.DataType {"ClusterStability" : dataloader .DataTypeString , "RandomSeed" : dataloader .DataTypeInteger , "WorkerNodes" : dataloader .DataTypeInteger ,
807+ "TotalNodes" : dataloader .DataTypeInteger , "Parallelism" : dataloader .DataTypeInteger },
808+ Rows : rows ,
809+ }
810+ fileName := filepath .Join (artifactDir , fmt .Sprintf ("run-suite-options%s-%s" , timeSuffix , dataloader .AutoDataLoaderSuffix ))
811+ err := dataloader .WriteDataFile (fileName , dataFile )
812+ if err != nil {
813+ logrus .WithError (err ).Warnf ("unable to write data file: %s" , fileName )
814+ }
815+ }
816+
782817func writeExtensionTestResults (tests []* testCase , dir , filePrefix , fileSuffix string , out io.Writer ) error {
783818 // Ensure the directory exists
784819 err := os .MkdirAll (dir , 0755 )
@@ -920,3 +955,31 @@ func determineExternalConnectivity(clusterConfig *clusterdiscovery.ClusterConfig
920955 }
921956 return "Direct"
922957}
958+
959+ func getClusterNodeCounts (ctx context.Context , config * rest.Config ) (int , int , error ) {
960+ kubeClient , err := kubernetes .NewForConfig (config )
961+ if err != nil {
962+ return 0 , 0 , err
963+ }
964+
965+ totalNodes := 0
966+ workerNodes := 0
967+
968+ nodes , err := kubeClient .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {LabelSelector : "node-role.kubernetes.io/worker" })
969+ if err != nil {
970+ return 0 , 0 , err
971+ }
972+
973+ workerNodes = len (nodes .Items )
974+ logrus .Infof ("Found %d worker nodes" , workerNodes )
975+
976+ nodes , err = kubeClient .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
977+ if err != nil {
978+ return 0 , 0 , err
979+ }
980+
981+ totalNodes = len (nodes .Items )
982+ logrus .Infof ("Found %d nodes" , totalNodes )
983+
984+ return totalNodes , workerNodes , nil
985+ }
0 commit comments