@@ -8,15 +8,16 @@ import (
88 "fmt"
99 "strings"
1010 "testing"
11-
12- "gopkg.in/yaml.v3"
11+ "time"
1312
1413 "github.com/spf13/pflag"
1514
1615 "github.com/NVIDIA/KAI-scheduler/cmd/scheduler/app/options"
1716 kaiv1 "github.com/NVIDIA/KAI-scheduler/pkg/apis/kai/v1"
1817 kaiv1qc "github.com/NVIDIA/KAI-scheduler/pkg/apis/kai/v1/queue_controller"
1918 kaiv1scheduler "github.com/NVIDIA/KAI-scheduler/pkg/apis/kai/v1/scheduler"
19+ usagedbapi "github.com/NVIDIA/KAI-scheduler/pkg/scheduler/cache/usagedb/api"
20+ "github.com/NVIDIA/KAI-scheduler/pkg/scheduler/conf"
2021
2122 "github.com/stretchr/testify/assert"
2223 "github.com/stretchr/testify/require"
@@ -25,6 +26,7 @@ import (
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627 "k8s.io/utils/ptr"
2728 "sigs.k8s.io/controller-runtime/pkg/client/fake"
29+ "sigs.k8s.io/yaml"
2830)
2931
3032func TestDeploymentForShard (t * testing.T ) {
@@ -187,7 +189,7 @@ func TestValidateJobDepthMap(t *testing.T) {
187189
188190 for _ , tt := range tests {
189191 t .Run (tt .name , func (t * testing.T ) {
190- innerConfig := config {
192+ innerConfig := conf. SchedulerConfiguration {
191193 Actions : strings .Join (tt .actions , ", " ),
192194 }
193195
@@ -431,6 +433,59 @@ tiers:
431433 },
432434 expectedErr : true ,
433435 },
436+ {
437+ name : "usage DB configuration" ,
438+ config : & kaiv1.Config {
439+ Spec : kaiv1.ConfigSpec {},
440+ },
441+ shard : & kaiv1.SchedulingShard {
442+ Spec : kaiv1.SchedulingShardSpec {
443+ UsageDBConfig : & usagedbapi.UsageDBConfig {
444+ ClientType : "prometheus" ,
445+ ConnectionString : "http://prometheus-operated.kai-scheduler.svc.cluster.local:9090" ,
446+ UsageParams : & usagedbapi.UsageParams {
447+ HalfLifePeriod : & metav1.Duration {Duration : 10 * time .Minute },
448+ WindowSize : & metav1.Duration {Duration : 10 * time .Minute },
449+ WindowType : ptr .To (usagedbapi .SlidingWindow ),
450+ },
451+ },
452+ },
453+ },
454+ expected : map [string ]string {
455+ "config.yaml" : `actions: allocate,consolidation,reclaim,preempt,stalegangeviction
456+ tiers:
457+ - plugins:
458+ - name: predicates
459+ - name: proportion
460+ - name: priority
461+ - name: nodeavailability
462+ - name: resourcetype
463+ - name: podaffinity
464+ - name: elastic
465+ - name: kubeflow
466+ - name: ray
467+ - name: subgrouporder
468+ - name: taskorder
469+ - name: nominatednode
470+ - name: dynamicresources
471+ - name: minruntime
472+ - name: topology
473+ - name: snapshot
474+ - name: gpupack
475+ - name: nodeplacement
476+ arguments:
477+ cpu: binpack
478+ gpu: binpack
479+ - name: gpusharingorder
480+ usageDBConfig:
481+ clientType: prometheus
482+ connectionString: http://prometheus-operated.kai-scheduler.svc.cluster.local:9090
483+ usageParams:
484+ halfLifePeriod: 10m
485+ windowSize: 10m
486+ windowType: sliding` ,
487+ },
488+ },
434489 }
435490
436491 for _ , tt := range tests {
@@ -454,15 +509,15 @@ tiers:
454509 require .True (t , found , "ConfigMap missing config.yaml" )
455510
456511 // Unmarshal expected YAML from test case
457- var expectedConfig config
512+ var expectedConfig conf. SchedulerConfiguration
458513 if _ , ok := tt .expected ["config.yaml" ]; ! ok {
459514 t .Fatal ("Test case must provide expected YAML for config.yaml" )
460515 }
461516 err = yaml .Unmarshal ([]byte (tt .expected ["config.yaml" ]), & expectedConfig )
462517 require .NoError (t , err , "Failed to unmarshal expected config" )
463518
464519 // Unmarshal actual YAML from ConfigMap
465- var actualConfig config
520+ var actualConfig conf. SchedulerConfiguration
466521 err = yaml .Unmarshal ([]byte (actualYAML ), & actualConfig )
467522 require .NoError (t , err , "Failed to unmarshal actual config" )
468523
@@ -606,3 +661,61 @@ func TestServiceAccountForScheduler(t *testing.T) {
606661 })
607662 }
608663}
664+
665+ func TestMarshalingShardVsConfig (t * testing.T ) {
666+ shardSpecString := `
667+ spec:
668+ partitionLabelValue: ""
669+ placementStrategy:
670+ cpu: binpack
671+ gpu: binpack
672+ usageDBConfig:
673+ clientType: prometheus
674+ connectionString: http://prometheus-operated.kai-scheduler.svc.cluster.local:9090
675+ usageParams:
676+ halfLifePeriod: 10m
677+ windowSize: 10m
678+ windowType: sliding
679+ `
680+
681+ shardSpec := & kaiv1.SchedulingShardSpec {}
682+ err := yaml .Unmarshal ([]byte (shardSpecString ), shardSpec )
683+ assert .NoError (t , err )
684+
685+ configString := `actions: allocate,consolidation,reclaim,preempt,stalegangeviction
686+ tiers:
687+ - plugins:
688+ - name: predicates
689+ - name: proportion
690+ - name: priority
691+ - name: nodeavailability
692+ - name: resourcetype
693+ - name: podaffinity
694+ - name: elastic
695+ - name: kubeflow
696+ - name: ray
697+ - name: subgrouporder
698+ - name: taskorder
699+ - name: nominatednode
700+ - name: dynamicresources
701+ - name: minruntime
702+ - name: topology
703+ - name: snapshot
704+ - name: gpupack
705+ - name: nodeplacement
706+ arguments:
707+ cpu: binpack
708+ gpu: binpack
709+ - name: gpusharingorder
710+ usageDBConfig:
711+ clientType: prometheus
712+ connectionString: http://prometheus-operated.kai-scheduler.svc.cluster.local:9090
713+ usageParams:
714+ halfLifePeriod: 10m
715+ windowSize: 10m
716+ windowType: sliding
717+ `
718+ config := & conf.SchedulerConfiguration {}
719+ err = yaml .Unmarshal ([]byte (configString ), config )
720+ assert .NoError (t , err )
721+ }
0 commit comments