Skip to content

Commit

Permalink
scheduler: add dynamic resource allocation plugin
Browse files Browse the repository at this point in the history
The plugin handles the interaction with ResourceClaims that are referenced by a
Pod.
  • Loading branch information
pohly committed Jul 8, 2022
1 parent be66345 commit 35bdb59
Show file tree
Hide file tree
Showing 13 changed files with 1,000 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/scheduler/apis/config/testing/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var PluginsV1beta2 = &config.Plugins{
{Name: names.InterPodAffinity},
{Name: names.VolumeBinding},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Filter: config.PluginSet{
Expand All @@ -56,11 +57,13 @@ var PluginsV1beta2 = &config.Plugins{
{Name: names.VolumeZone},
{Name: names.PodTopologySpread},
{Name: names.InterPodAffinity},
{Name: names.DynamicResources},
},
},
PostFilter: config.PluginSet{
Enabled: []config.Plugin{
{Name: names.DefaultPreemption},
{Name: names.DynamicResources},
},
},
PreScore: config.PluginSet{
Expand All @@ -69,6 +72,7 @@ var PluginsV1beta2 = &config.Plugins{
{Name: names.PodTopologySpread},
{Name: names.TaintToleration},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Score: config.PluginSet{
Expand All @@ -88,6 +92,7 @@ var PluginsV1beta2 = &config.Plugins{
Reserve: config.PluginSet{
Enabled: []config.Plugin{
{Name: names.VolumeBinding},
{Name: names.DynamicResources},
},
},
PreBind: config.PluginSet{
Expand All @@ -100,6 +105,11 @@ var PluginsV1beta2 = &config.Plugins{
{Name: names.DefaultBinder},
},
},
PostBind: config.PluginSet{
Enabled: []config.Plugin{
{Name: names.DynamicResources},
},
},
}

// PluginConfigsV1beta2 default plugin configurations. This could get versioned, but since
Expand Down
10 changes: 10 additions & 0 deletions pkg/scheduler/apis/config/v1beta2/default_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func getDefaultPlugins() *v1beta2.Plugins {
{Name: names.InterPodAffinity},
{Name: names.VolumeBinding},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Filter: v1beta2.PluginSet{
Expand All @@ -62,11 +63,13 @@ func getDefaultPlugins() *v1beta2.Plugins {
{Name: names.VolumeZone},
{Name: names.PodTopologySpread},
{Name: names.InterPodAffinity},
{Name: names.DynamicResources},
},
},
PostFilter: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.DefaultPreemption},
{Name: names.DynamicResources},
},
},
PreScore: v1beta2.PluginSet{
Expand All @@ -75,6 +78,7 @@ func getDefaultPlugins() *v1beta2.Plugins {
{Name: names.PodTopologySpread},
{Name: names.TaintToleration},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Score: v1beta2.PluginSet{
Expand All @@ -94,6 +98,7 @@ func getDefaultPlugins() *v1beta2.Plugins {
Reserve: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.VolumeBinding},
{Name: names.DynamicResources},
},
},
PreBind: v1beta2.PluginSet{
Expand All @@ -106,6 +111,11 @@ func getDefaultPlugins() *v1beta2.Plugins {
{Name: names.DefaultBinder},
},
},
PostBind: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.DynamicResources},
},
},
}
applyFeatureGates(plugins)

Expand Down
10 changes: 10 additions & 0 deletions pkg/scheduler/apis/config/v1beta2/default_plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: names.InterPodAffinity},
{Name: names.VolumeBinding},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Filter: v1beta2.PluginSet{
Expand All @@ -70,11 +71,13 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: names.VolumeZone},
{Name: names.PodTopologySpread},
{Name: names.InterPodAffinity},
{Name: names.DynamicResources},
},
},
PostFilter: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.DefaultPreemption},
{Name: names.DynamicResources},
},
},
PreScore: v1beta2.PluginSet{
Expand All @@ -83,6 +86,7 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: names.PodTopologySpread},
{Name: names.TaintToleration},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Score: v1beta2.PluginSet{
Expand All @@ -99,6 +103,7 @@ func TestApplyFeatureGates(t *testing.T) {
Reserve: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.VolumeBinding},
{Name: names.DynamicResources},
},
},
PreBind: v1beta2.PluginSet{
Expand All @@ -111,6 +116,11 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: names.DefaultBinder},
},
},
PostBind: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.DynamicResources},
},
},
},
},
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/scheduler/apis/config/v1beta2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func TestSchedulerDefaults(t *testing.T) {
{Name: names.InterPodAffinity},
{Name: names.VolumeBinding},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Filter: v1beta2.PluginSet{
Expand All @@ -358,11 +359,13 @@ func TestSchedulerDefaults(t *testing.T) {
{Name: names.VolumeZone},
{Name: names.PodTopologySpread},
{Name: names.InterPodAffinity},
{Name: names.DynamicResources},
},
},
PostFilter: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.DefaultPreemption},
{Name: names.DynamicResources},
},
},
PreScore: v1beta2.PluginSet{
Expand All @@ -371,6 +374,7 @@ func TestSchedulerDefaults(t *testing.T) {
{Name: names.PodTopologySpread},
{Name: names.TaintToleration},
{Name: names.NodeAffinity},
{Name: names.DynamicResources},
},
},
Score: v1beta2.PluginSet{
Expand All @@ -387,6 +391,7 @@ func TestSchedulerDefaults(t *testing.T) {
Reserve: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: names.VolumeBinding},
{Name: names.DynamicResources},
},
},
PreBind: v1beta2.PluginSet{
Expand All @@ -399,6 +404,11 @@ func TestSchedulerDefaults(t *testing.T) {
{Name: "BarPlugin"},
},
},
PostBind: v1beta2.PluginSet{
Enabled: []v1beta2.Plugin{
{Name: "DynamicResources"},
},
},
},
PluginConfig: pluginConfigs,
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/scheduler/eventhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ func addAllEventHandlers(
informerFactory.Core().V1().PersistentVolumeClaims().Informer().AddEventHandler(
buildEvtResHandler(at, framework.PersistentVolumeClaim, "Pvc"),
)
case framework.PodScheduling:
informerFactory.Core().V1().PodSchedulings().Informer().AddEventHandler(
buildEvtResHandler(at, framework.PodScheduling, "PodScheduling"),
)
case framework.ResourceClaim:
informerFactory.Core().V1().ResourceClaims().Informer().AddEventHandler(
buildEvtResHandler(at, framework.ResourceClaim, "ResourceClaim"),
)
case framework.StorageClass:
if at&framework.Add != 0 {
informerFactory.Storage().V1().StorageClasses().Informer().AddEventHandler(
Expand Down
11 changes: 11 additions & 0 deletions pkg/scheduler/framework/plugins/dynamicresources/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See the OWNERS docs at https://go.k8s.io/owners

approvers:
- @klueska
- @pohly
reviewers:
- @klueska
- @pohly
- @bart0sh
labels:
- sig/node
53 changes: 53 additions & 0 deletions pkg/scheduler/framework/plugins/dynamicresources/builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package dynamicresources

import (
"encoding/json"
"fmt"

corev1 "k8s.io/api/core/v1"
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
)

func buildNode(in *corev1ac.NodeApplyConfiguration) *corev1.Node {
out := &corev1.Node{}
build(in, out)
return out
}

func buildPod(in *corev1ac.PodApplyConfiguration) *corev1.Pod {
out := &corev1.Pod{}
build(in, out)
return out
}

func buildResourceClaim(in *corev1ac.ResourceClaimApplyConfiguration) *corev1.ResourceClaim {
out := &corev1.ResourceClaim{}
build(in, out)
return out
}

func build(in, out interface{}) {
buffer, err := json.Marshal(in)
if err != nil {
panic(fmt.Errorf("encoding %T as JSON: %v", in, err))
}
if err := json.Unmarshal(buffer, out); err != nil {
panic(fmt.Errorf("decoding %T from JSON: %v", out, err))
}
}
Loading

0 comments on commit 35bdb59

Please sign in to comment.