Skip to content

Commit 30c978b

Browse files
committed
enable the schedule plugin if the featuregate is enabled
enable the schedule plugin if the featuregate DynamicResourceAllocation is enabled
1 parent 8740a60 commit 30c978b

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

pkg/operator/targetconfigcontroller/targetconfigcontroller.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (c TargetConfigController) sync(ctx context.Context, syncCtx factory.SyncCo
123123
func createTargetConfigController_v311_00_to_latest(ctx context.Context, syncCtx factory.SyncContext, c TargetConfigController, operatorSpec *operatorv1.StaticPodOperatorSpec) (bool, error) {
124124
errors := []error{}
125125

126-
_, _, err := manageKubeSchedulerConfigMap_v311_00_to_latest(ctx, c.kubeClient.CoreV1(), syncCtx.Recorder(), c.configSchedulerLister)
126+
_, _, err := manageKubeSchedulerConfigMap_v311_00_to_latest(ctx, c.featureGates, c.kubeClient.CoreV1(), syncCtx.Recorder(), c.configSchedulerLister)
127127
if err != nil {
128128
errors = append(errors, fmt.Errorf("%q: %v", "configmap", err))
129129
}
@@ -168,7 +168,7 @@ func createTargetConfigController_v311_00_to_latest(ctx context.Context, syncCtx
168168
return false, nil
169169
}
170170

171-
func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, client corev1client.ConfigMapsGetter, recorder events.Recorder, configSchedulerLister configlistersv1.SchedulerLister) (*corev1.ConfigMap, bool, error) {
171+
func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, featureGates featuregates.FeatureGate, client corev1client.ConfigMapsGetter, recorder events.Recorder, configSchedulerLister configlistersv1.SchedulerLister) (*corev1.ConfigMap, bool, error) {
172172
configMap := resourceread.ReadConfigMapV1OrDie(bindata.MustAsset("assets/kube-scheduler/cm.yaml"))
173173

174174
var kubeSchedulerConfiguration []byte
@@ -199,19 +199,30 @@ func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, client
199199
return nil, false, err
200200
}
201201

202+
var enableDRAPlugin bool
202203
switch config.Spec.ProfileCustomizations.DynamicResourceAllocation {
203204
case v1.DRAEnablementEnabled:
205+
enableDRAPlugin = true
206+
case "", v1.DRAEnablementDisabled:
207+
// no-op
208+
default:
209+
return nil, false, fmt.Errorf("dynamicResourceAllocation customization %q not recognized", config.Spec.ProfileCustomizations.DynamicResourceAllocation)
210+
}
211+
// if the feature gate DynamicResourceAllocation is enabled, we will enable the plugin
212+
if !enableDRAPlugin {
213+
if featureGates.Enabled("DynamicResourceAllocation") {
214+
enableDRAPlugin = true
215+
klog.Infof("feature gate DynamicResourceAllocation is set, enabling the scheduler plugin")
216+
}
217+
}
218+
if enableDRAPlugin {
204219
if len(schedulerConfiguration.Profiles) == 0 {
205220
schedulerConfiguration.Profiles = []schedulerconfigv1.KubeSchedulerProfile{{}}
206221
}
207222
if schedulerConfiguration.Profiles[0].Plugins == nil {
208223
schedulerConfiguration.Profiles[0].Plugins = &schedulerconfigv1.Plugins{}
209224
}
210225
schedulerConfiguration.Profiles[0].Plugins.MultiPoint.Enabled = append(schedulerConfiguration.Profiles[0].Plugins.MultiPoint.Enabled, schedulerconfigv1.Plugin{Name: "DynamicResources"})
211-
case "", v1.DRAEnablementDisabled:
212-
// no-op
213-
default:
214-
return nil, false, fmt.Errorf("dynamicResourceAllocation customization %q not recognized", config.Spec.ProfileCustomizations.DynamicResourceAllocation)
215226
}
216227

217228
schedulerConfigurationBytes, err := yaml.Marshal(schedulerConfiguration)

pkg/operator/targetconfigcontroller/targetconfigcontroller_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func Test_manageKubeSchedulerConfigMap_v311_00_to_latest(t *testing.T) {
106106
tests := []struct {
107107
name string
108108
args args
109+
featureGates featuregates.FeatureGate
109110
want *corev1.ConfigMap
110111
wantConfig string
111112
wantSchedProfiles []schedulerconfigv1.KubeSchedulerProfile
@@ -335,11 +336,59 @@ func Test_manageKubeSchedulerConfigMap_v311_00_to_latest(t *testing.T) {
335336
want1: true,
336337
wantErr: false,
337338
},
339+
{
340+
name: "high-node-utilization-dra-feature-gate-enabled",
341+
args: args{
342+
recorder: fakeRecorder,
343+
configSchedulerLister: &fakeSchedConfigLister{
344+
Items: map[string]*configv1.Scheduler{"cluster": {
345+
Spec: configv1.SchedulerSpec{
346+
Profile: configv1.HighNodeUtilization,
347+
},
348+
},
349+
},
350+
},
351+
},
352+
featureGates: featuregates.NewFeatureGate([]configv1.FeatureGateName{"DynamicResourceAllocation"}, nil),
353+
wantSchedProfiles: []schedulerconfigv1.KubeSchedulerProfile{
354+
{
355+
SchedulerName: ptr.To[string]("default-scheduler"),
356+
PluginConfig: []schedulerconfigv1.PluginConfig{
357+
{
358+
Name: "NodeResourcesFit",
359+
Args: runtime.RawExtension{Raw: []uint8(`{"scoringStrategy":{"type":"MostAllocated"}}`)},
360+
},
361+
},
362+
Plugins: &schedulerconfigv1.Plugins{
363+
Score: schedulerconfigv1.PluginSet{
364+
Enabled: []schedulerconfigv1.Plugin{
365+
{Name: "NodeResourcesFit", Weight: ptr.To[int32](5)},
366+
},
367+
Disabled: []schedulerconfigv1.Plugin{
368+
{Name: "NodeResourcesBalancedAllocation"},
369+
},
370+
},
371+
MultiPoint: schedulerconfigv1.PluginSet{
372+
Enabled: []schedulerconfigv1.Plugin{
373+
{Name: "DynamicResources"},
374+
},
375+
},
376+
},
377+
},
378+
},
379+
want1: true,
380+
wantErr: false,
381+
},
338382
}
339383
for _, tt := range tests {
340384
t.Run(tt.name, func(t *testing.T) {
385+
featureGates := tt.featureGates
386+
if featureGates == nil {
387+
// use a default feature gate where DynamicResourceAllocation is disabled
388+
featureGates = featuregates.NewFeatureGate(nil, []configv1.FeatureGateName{"DynamicResourceAllocation"})
389+
}
341390
// need a client for each test
342-
got, got1, err := manageKubeSchedulerConfigMap_v311_00_to_latest(context.TODO(), fake.NewSimpleClientset().CoreV1(), tt.args.recorder, tt.args.configSchedulerLister)
391+
got, got1, err := manageKubeSchedulerConfigMap_v311_00_to_latest(context.TODO(), featureGates, fake.NewSimpleClientset().CoreV1(), tt.args.recorder, tt.args.configSchedulerLister)
343392
if (err != nil) != tt.wantErr {
344393
t.Errorf("manageKubeSchedulerConfigMap_v311_00_to_latest() error = %v, wantErr %v", err, tt.wantErr)
345394
return

0 commit comments

Comments
 (0)