Skip to content

Commit

Permalink
Profile customization: experimental enabling of DRA
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Jan 26, 2024
1 parent 68649c7 commit 9f8749c
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 62 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ The default list of scheduling profiles as provided by the kube-scheduler.

This profiles disabled all scoring plugins.

## Profile Customizations (TechnicalPreview)

Customizations of existing profiles are available under the `.spec.profileCustomizations` field:

| Name | Type | Description |
| ---- | ---- | ----------- |
| `experimentalDynamicResourceAllocation` | `string` | Experimental: Enable Dynamic Resource Allocation functionality |

E.g.

```yaml
apiVersion: config.openshift.io/v1
kind: Scheduler
metadata:
name: cluster
spec:
mastersSchedulable: false
policy:
name: ""
profile: HighNodeUtilization
profileCustomizations:
experimentalDynamicResourceAllocation: Enabled
...
```


## Debugging

Operator also expose events that can help debugging issues. To get operator events, run following command:
Expand Down
50 changes: 35 additions & 15 deletions pkg/operator/targetconfigcontroller/targetconfigcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/ghodss/yaml"
v1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
configinformers "github.com/openshift/client-go/config/informers/externalversions"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/openshift/library-go/pkg/operator/resource/resourceread"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
"github.com/openshift/library-go/pkg/operator/v1helpers"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -32,6 +34,7 @@ import (
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/klog/v2"
schedulerconfigv1 "k8s.io/kube-scheduler/config/v1"
)

type TargetConfigController struct {
Expand Down Expand Up @@ -172,25 +175,42 @@ func manageKubeSchedulerConfigMap_v311_00_to_latest(ctx context.Context, client
if err != nil {
return nil, false, err
}
// Scheduler Policy API has been removed in k8s 1.23
// Still keep the CRD field for compatibility, but it does nothing now
if len(config.Spec.Policy.Name) > 0 {
return nil, false, fmt.Errorf("scheduler Policy config has been removed upstream, this field remains for CRD compatibility but does nothing now. Please use a Profile instead (defaulting to LowNodeUtilization).")
} else {
switch config.Spec.Profile {
case v1.LowNodeUtilization, "":
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-lownodeutilization.yaml")
case v1.HighNodeUtilization:
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-highnodeutilization.yaml")
case v1.NoScoring:
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-noscoring.yaml")
default:
return nil, false, fmt.Errorf("profile %q not recognized", config.Spec.Profile)

switch config.Spec.Profile {
case v1.LowNodeUtilization, "":
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-lownodeutilization.yaml")
case v1.HighNodeUtilization:
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-highnodeutilization.yaml")
case v1.NoScoring:
kubeSchedulerConfiguration = bindata.MustAsset("assets/config/defaultconfig-postbootstrap-noscoring.yaml")
default:
return nil, false, fmt.Errorf("profile %q not recognized", config.Spec.Profile)
}

schedulerConfiguration := &schedulerconfigv1.KubeSchedulerConfiguration{}
if err := yaml.Unmarshal(kubeSchedulerConfiguration, schedulerConfiguration); err != nil {
return nil, false, err
}

if config.Spec.ProfileCustomizations != nil {
if config.Spec.ProfileCustomizations.ExperimentalDynamicResourceAllocation == v1.DRAEnablementEnabled {
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"})
}
}

schedulerConfigurationBytes, err := yaml.Marshal(schedulerConfiguration)
if err != nil {
return nil, false, err
}

defaultConfig := bindata.MustAsset("assets/config/defaultconfig.yaml")
requiredConfigMap, _, err := resourcemerge.MergeConfigMap(configMap, "config.yaml", nil, kubeSchedulerConfiguration, defaultConfig)
requiredConfigMap, _, err := resourcemerge.MergeConfigMap(configMap, "config.yaml", nil, schedulerConfigurationBytes, defaultConfig)
if err != nil {
return nil, false, err
}
Expand Down

0 comments on commit 9f8749c

Please sign in to comment.