Skip to content

Commit 22cc61d

Browse files
authored
Remove default option for batch scheduler name (#2371)
1 parent b8f6d06 commit 22cc61d

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed

helm-chart/kuberay-operator/values.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ batchScheduler:
7878
# Deprecated. This option will be removed in the future.
7979
# Note, for backwards compatibility. When it sets to true, it enables volcano scheduler integration.
8080
enabled: false
81-
# Name of the scheduler, currently supported "default", "volcano" and "yunikorn",
82-
# set the customized scheduler name, e.g "volcano" or "yunikorn", do not set
81+
# Set the customized scheduler name, supported values are "volcano" or "yunikorn", do not set
8382
# "batchScheduler.enabled=true" at the same time as it will override this option.
84-
name: default
83+
name: ""
8584

8685
featureGates:
8786
- name: RayClusterStatusConditions

ray-operator/apis/config/v1alpha1/config_utils.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ func ValidateBatchSchedulerConfig(logger logr.Logger, config Configuration) erro
1717
}
1818

1919
if len(config.BatchScheduler) > 0 {
20-
// default option, no-opt.
21-
if config.BatchScheduler == "default" {
22-
return nil
23-
}
24-
2520
// if a customized scheduler is configured, check it is supported
2621
if config.BatchScheduler == volcano.GetPluginName() || config.BatchScheduler == yunikorn.GetPluginName() {
2722
logger.Info("Feature flag batch-scheduler is enabled",
@@ -30,5 +25,6 @@ func ValidateBatchSchedulerConfig(logger logr.Logger, config Configuration) erro
3025
return fmt.Errorf("scheduler is not supported, name=%s", config.BatchScheduler)
3126
}
3227
}
28+
3329
return nil
3430
}

ray-operator/apis/config/v1alpha1/config_utils_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ func TestValidateBatchSchedulerConfig(t *testing.T) {
7171
},
7272
wantErr: true,
7373
},
74+
{
75+
name: "invalid option, invalid scheduler name default",
76+
args: args{
77+
logger: testr.New(t),
78+
config: Configuration{
79+
EnableBatchScheduler: false,
80+
BatchScheduler: "default",
81+
},
82+
},
83+
wantErr: true,
84+
},
7485
}
7586

7687
for _, tt := range tests {

ray-operator/controllers/ray/batchscheduler/schedulermanager.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package batchscheduler
22

33
import (
4+
"fmt"
45
"sync"
56

67
"k8s.io/apimachinery/pkg/runtime"
@@ -28,7 +29,11 @@ type SchedulerManager struct {
2829
// NewSchedulerManager maintains a specific scheduler plugin based on config
2930
func NewSchedulerManager(rayConfigs configapi.Configuration, config *rest.Config) (*SchedulerManager, error) {
3031
// init the scheduler factory from config
31-
factory := getSchedulerFactory(rayConfigs)
32+
factory, err := getSchedulerFactory(rayConfigs)
33+
if err != nil {
34+
return nil, err
35+
}
36+
3237
scheduler, err := factory.New(config)
3338
if err != nil {
3439
return nil, err
@@ -44,20 +49,25 @@ func NewSchedulerManager(rayConfigs configapi.Configuration, config *rest.Config
4449
return &manager, nil
4550
}
4651

47-
func getSchedulerFactory(rayConfigs configapi.Configuration) schedulerinterface.BatchSchedulerFactory {
52+
func getSchedulerFactory(rayConfigs configapi.Configuration) (schedulerinterface.BatchSchedulerFactory, error) {
4853
var factory schedulerinterface.BatchSchedulerFactory
49-
// init with the default factory
50-
factory = &schedulerinterface.DefaultBatchSchedulerFactory{}
54+
5155
// when a batch scheduler name is provided
56+
// only support a white list of names, empty value is the default value
57+
// it throws error if an unknown name is provided
5258
if len(rayConfigs.BatchScheduler) > 0 {
5359
switch rayConfigs.BatchScheduler {
5460
case volcano.GetPluginName():
5561
factory = &volcano.VolcanoBatchSchedulerFactory{}
5662
case yunikorn.GetPluginName():
5763
factory = &yunikorn.YuniKornSchedulerFactory{}
5864
default:
59-
factory = &schedulerinterface.DefaultBatchSchedulerFactory{}
65+
return nil, fmt.Errorf("the scheduler is not supported, name=%s", rayConfigs.BatchScheduler)
6066
}
67+
} else {
68+
// empty is the default value, when not set
69+
// use DefaultBatchSchedulerFactory, it's a no-opt factory
70+
factory = &schedulerinterface.DefaultBatchSchedulerFactory{}
6171
}
6272

6373
// legacy option, if this is enabled, register volcano
@@ -66,7 +76,7 @@ func getSchedulerFactory(rayConfigs configapi.Configuration) schedulerinterface.
6676
factory = &volcano.VolcanoBatchSchedulerFactory{}
6777
}
6878

69-
return factory
79+
return factory, nil
7080
}
7181

7282
func (batch *SchedulerManager) GetSchedulerForCluster(app *rayv1.RayCluster) (schedulerinterface.BatchScheduler, error) {

ray-operator/controllers/ray/batchscheduler/schedulermanager_test.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"reflect"
55
"testing"
66

7+
"github.com/stretchr/testify/assert"
8+
79
"github.com/ray-project/kuberay/ray-operator/apis/config/v1alpha1"
810
schedulerinterface "github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/interface"
911
"github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/volcano"
@@ -19,16 +21,17 @@ func TestGetSchedulerFactory(t *testing.T) {
1921
rayConfigs v1alpha1.Configuration
2022
}
2123
tests := []struct {
22-
want reflect.Type
23-
name string
24-
args args
24+
want reflect.Type
25+
name string
26+
expectedErrMsg string
27+
args args
2528
}{
2629
{
27-
name: "enableBatchScheduler=false, batchScheduler set to default",
30+
name: "enableBatchScheduler=false, batchScheduler=''",
2831
args: args{
2932
rayConfigs: v1alpha1.Configuration{
3033
EnableBatchScheduler: false,
31-
BatchScheduler: schedulerinterface.GetDefaultPluginName(),
34+
BatchScheduler: "",
3235
},
3336
},
3437
want: reflect.TypeOf(DefaultFactory),
@@ -80,6 +83,15 @@ func TestGetSchedulerFactory(t *testing.T) {
8083
},
8184
want: reflect.TypeOf(VolcanoFactory),
8285
},
86+
{
87+
name: "enableBatchScheduler not set, batchScheduler set to unknown value",
88+
args: args{
89+
rayConfigs: v1alpha1.Configuration{
90+
BatchScheduler: "unknown-scheduler-name",
91+
},
92+
},
93+
expectedErrMsg: "the scheduler is not supported, name=unknown-scheduler-name",
94+
},
8395
{
8496
// for backwards compatibility, if enableBatchScheduler=true, always use volcano
8597
name: "enableBatchScheduler=true, batchScheduler set to yunikorn",
@@ -108,7 +120,7 @@ func TestGetSchedulerFactory(t *testing.T) {
108120
args: args{
109121
rayConfigs: v1alpha1.Configuration{
110122
EnableBatchScheduler: true,
111-
BatchScheduler: schedulerinterface.GetDefaultPluginName(),
123+
BatchScheduler: "",
112124
},
113125
},
114126
want: reflect.TypeOf(VolcanoFactory),
@@ -117,7 +129,13 @@ func TestGetSchedulerFactory(t *testing.T) {
117129

118130
for _, tt := range tests {
119131
t.Run(tt.name, func(t *testing.T) {
120-
if got := getSchedulerFactory(tt.args.rayConfigs); reflect.TypeOf(got) != tt.want {
132+
got, err := getSchedulerFactory(tt.args.rayConfigs)
133+
if len(tt.expectedErrMsg) > 0 {
134+
assert.Errorf(t, err, tt.expectedErrMsg)
135+
return
136+
}
137+
138+
if reflect.TypeOf(got) != tt.want {
121139
t.Errorf("getSchedulerFactory() = %v, want %v", got, tt.want)
122140
}
123141
})

ray-operator/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func main() {
9191
flag.StringVar(&logStdoutEncoder, "log-stdout-encoder", "json",
9292
"Encoder to use for logging stdout. Valid values are 'json' and 'console'. Defaults to 'json'")
9393
flag.BoolVar(&enableBatchScheduler, "enable-batch-scheduler", false,
94-
"(Deprecated) Enable batch scheduler. Currently is volcano, which supports gang scheduler policy.")
95-
flag.StringVar(&batchScheduler, "batch-scheduler", "default",
96-
"Batch scheduler name, supported values are default, volcano, yunikorn.")
94+
"(Deprecated) Enable batch scheduler. Currently is volcano, which supports gang scheduler policy. Please use --batch-scheduler instead.")
95+
flag.StringVar(&batchScheduler, "batch-scheduler", "",
96+
"Batch scheduler name, supported values are volcano and yunikorn.")
9797
flag.StringVar(&configFile, "config", "", "Path to structured config file. Flags are ignored if config file is set.")
9898
flag.BoolVar(&useKubernetesProxy, "use-kubernetes-proxy", false,
9999
"Use Kubernetes proxy subresource when connecting to the Ray Head node.")

0 commit comments

Comments
 (0)