Skip to content

OCPNODE-3192: enable the scheduler plugin if the feature gate DynamicResourceAllocation is enabled #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions pkg/operator/targetconfigcontroller/targetconfigcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c TargetConfigController) sync(ctx context.Context, syncCtx factory.SyncCo
func createTargetConfigController_v311_00_to_latest(ctx context.Context, syncCtx factory.SyncContext, c TargetConfigController, operatorSpec *operatorv1.StaticPodOperatorSpec) (bool, error) {
errors := []error{}

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

func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, client corev1client.ConfigMapsGetter, recorder events.Recorder, configSchedulerLister configlistersv1.SchedulerLister) (*corev1.ConfigMap, bool, error) {
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) {
configMap := resourceread.ReadConfigMapV1OrDie(bindata.MustAsset("assets/kube-scheduler/cm.yaml"))

var kubeSchedulerConfiguration []byte
Expand Down Expand Up @@ -199,19 +199,29 @@ func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, client
return nil, false, err
}

var enableDRAPlugin bool
switch config.Spec.ProfileCustomizations.DynamicResourceAllocation {
case v1.DRAEnablementEnabled:
enableDRAPlugin = true
case "", v1.DRAEnablementDisabled:
// no-op
default:
return nil, false, fmt.Errorf("dynamicResourceAllocation customization %q not recognized", config.Spec.ProfileCustomizations.DynamicResourceAllocation)
}
// if the feature gate DynamicResourceAllocation is enabled, we will enable the plugin
if !enableDRAPlugin {
if featureGates.Enabled("DynamicResourceAllocation") {
enableDRAPlugin = true
}
}
if enableDRAPlugin {
if len(schedulerConfiguration.Profiles) == 0 {
schedulerConfiguration.Profiles = []schedulerconfigv1.KubeSchedulerProfile{{}}
}
if schedulerConfiguration.Profiles[0].Plugins == nil {
schedulerConfiguration.Profiles[0].Plugins = &schedulerconfigv1.Plugins{}
}
schedulerConfiguration.Profiles[0].Plugins.MultiPoint.Enabled = append(schedulerConfiguration.Profiles[0].Plugins.MultiPoint.Enabled, schedulerconfigv1.Plugin{Name: "DynamicResources"})
case "", v1.DRAEnablementDisabled:
// no-op
default:
return nil, false, fmt.Errorf("dynamicResourceAllocation customization %q not recognized", config.Spec.ProfileCustomizations.DynamicResourceAllocation)
}

schedulerConfigurationBytes, err := yaml.Marshal(schedulerConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func Test_manageKubeSchedulerConfigMap_v311_00_to_latest(t *testing.T) {
tests := []struct {
name string
args args
featureGates featuregates.FeatureGate
want *corev1.ConfigMap
wantConfig string
wantSchedProfiles []schedulerconfigv1.KubeSchedulerProfile
Expand Down Expand Up @@ -335,11 +336,59 @@ func Test_manageKubeSchedulerConfigMap_v311_00_to_latest(t *testing.T) {
want1: true,
wantErr: false,
},
{
name: "high-node-utilization-dra-feature-gate-enabled",
args: args{
recorder: fakeRecorder,
configSchedulerLister: &fakeSchedConfigLister{
Items: map[string]*configv1.Scheduler{"cluster": {
Spec: configv1.SchedulerSpec{
Profile: configv1.HighNodeUtilization,
},
},
},
},
},
featureGates: featuregates.NewFeatureGate([]configv1.FeatureGateName{"DynamicResourceAllocation"}, nil),
wantSchedProfiles: []schedulerconfigv1.KubeSchedulerProfile{
{
SchedulerName: ptr.To[string]("default-scheduler"),
PluginConfig: []schedulerconfigv1.PluginConfig{
{
Name: "NodeResourcesFit",
Args: runtime.RawExtension{Raw: []uint8(`{"scoringStrategy":{"type":"MostAllocated"}}`)},
},
},
Plugins: &schedulerconfigv1.Plugins{
Score: schedulerconfigv1.PluginSet{
Enabled: []schedulerconfigv1.Plugin{
{Name: "NodeResourcesFit", Weight: ptr.To[int32](5)},
},
Disabled: []schedulerconfigv1.Plugin{
{Name: "NodeResourcesBalancedAllocation"},
},
},
MultiPoint: schedulerconfigv1.PluginSet{
Enabled: []schedulerconfigv1.Plugin{
{Name: "DynamicResources"},
},
},
},
},
},
want1: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
featureGates := tt.featureGates
if featureGates == nil {
// use a default feature gate where DynamicResourceAllocation is disabled
featureGates = featuregates.NewFeatureGate(nil, []configv1.FeatureGateName{"DynamicResourceAllocation"})
}
// need a client for each test
got, got1, err := manageKubeSchedulerConfigMap_v311_00_to_latest(context.TODO(), fake.NewSimpleClientset().CoreV1(), tt.args.recorder, tt.args.configSchedulerLister)
got, got1, err := manageKubeSchedulerConfigMap_v311_00_to_latest(context.TODO(), featureGates, fake.NewSimpleClientset().CoreV1(), tt.args.recorder, tt.args.configSchedulerLister)
if (err != nil) != tt.wantErr {
t.Errorf("manageKubeSchedulerConfigMap_v311_00_to_latest() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down