@@ -61,6 +61,8 @@ type options struct {
61
61
values []string
62
62
clusters []string
63
63
remarshal bool
64
+ shardIndex int
65
+ shardCount int
64
66
}
65
67
66
68
func Command () * cobra.Command {
@@ -268,7 +270,10 @@ func Command() *cobra.Command {
268
270
}
269
271
fmt .Fprintf (out , "- NoCluster %v\n " , options .noCluster )
270
272
fmt .Fprintf (out , "- PauseOnFailure %v\n " , options .pauseOnFailure )
271
- // loading tests
273
+ if options .shardCount > 0 {
274
+ fmt .Fprintf (out , "- Shard %v / %v\n " , options .shardIndex , options .shardCount )
275
+ }
276
+ // load tests
272
277
fmt .Fprintln (out , "Loading tests..." )
273
278
if err := fsutils .CheckFolders (options .testDirs ... ); err != nil {
274
279
return err
@@ -285,6 +290,16 @@ func Command() *cobra.Command {
285
290
if err != nil {
286
291
return err
287
292
}
293
+ // TODO: we may want to find a sort key here ?
294
+ if options .shardCount > 0 && options .shardIndex < options .shardCount {
295
+ shardLen := float64 (len (tests )) / float64 (options .shardCount )
296
+ shardStart := int (shardLen * float64 (options .shardIndex ))
297
+ shardEnd := int (shardLen * float64 (options .shardIndex + 1 ))
298
+ if options .shardIndex == options .shardCount - 1 {
299
+ shardEnd = len (tests )
300
+ }
301
+ tests = tests [shardStart :shardEnd ]
302
+ }
288
303
var testToRun []discovery.Test
289
304
for _ , test := range tests {
290
305
if test .Err != nil {
@@ -294,7 +309,7 @@ func Command() *cobra.Command {
294
309
testToRun = append (testToRun , test )
295
310
}
296
311
}
297
- // loading tests
312
+ // load values
298
313
fmt .Fprintln (out , "Loading values..." )
299
314
values , err := values .Load (options .values ... )
300
315
if err != nil {
@@ -378,6 +393,9 @@ func Command() *cobra.Command {
378
393
cmd .Flags ().StringSliceVar (& options .selector , "selector" , nil , "Selector (label query) to filter on" )
379
394
// external values
380
395
cmd .Flags ().StringSliceVar (& options .values , "values" , nil , "Values passed to the tests" )
396
+ // sharding
397
+ cmd .Flags ().IntVar (& options .shardIndex , "shard-index" , 0 , "Current shard index (if `--shard-count` > 0)" )
398
+ cmd .Flags ().IntVar (& options .shardCount , "shard-count" , 0 , "Number of shards" )
381
399
// others
382
400
cmd .Flags ().BoolVar (& options .noColor , "no-color" , false , "Removes output colors" )
383
401
cmd .Flags ().BoolVar (& options .remarshal , "remarshal" , false , "Remarshals tests yaml to apply anchors before parsing" )
0 commit comments