Skip to content

Commit 98d1e24

Browse files
Use internal config types in scheduling plugin args
Signed-off-by: Aldo Culquicondor <[email protected]>
1 parent 6b153dc commit 98d1e24

29 files changed

+488
-426
lines changed

cmd/kube-scheduler/app/options/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ go_library(
1919
"//pkg/scheduler/apis/config/scheme:go_default_library",
2020
"//pkg/scheduler/apis/config/v1alpha2:go_default_library",
2121
"//pkg/scheduler/apis/config/validation:go_default_library",
22-
"//pkg/scheduler/framework/plugins:go_default_library",
2322
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
2423
"//staging/src/k8s.io/api/core/v1:go_default_library",
2524
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",

cmd/kube-scheduler/app/options/deprecated.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import (
2121

2222
"github.com/spf13/pflag"
2323
"k8s.io/apimachinery/pkg/util/validation/field"
24-
kubeschedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
2524
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
2625
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
27-
"k8s.io/kubernetes/pkg/scheduler/framework/plugins"
2826
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
2927
)
3028

@@ -129,10 +127,13 @@ func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfig
129127
profile.SchedulerName = o.SchedulerName
130128
}
131129
if o.HardPodAffinitySymmetricWeight != interpodaffinity.DefaultHardPodAffinityWeight {
132-
args := kubeschedulerv1alpha2.InterPodAffinityArgs{
133-
HardPodAffinityWeight: &o.HardPodAffinitySymmetricWeight,
130+
plCfg := kubeschedulerconfig.PluginConfig{
131+
Name: interpodaffinity.Name,
132+
Args: &kubeschedulerconfig.InterPodAffinityArgs{
133+
HardPodAffinityWeight: o.HardPodAffinitySymmetricWeight,
134+
},
134135
}
135-
profile.PluginConfig = append(profile.PluginConfig, plugins.NewPluginConfig(interpodaffinity.Name, args))
136+
profile.PluginConfig = append(profile.PluginConfig, plCfg)
136137
}
137138
return nil
138139
}

cmd/kube-scheduler/app/options/options_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ profiles:
203203
disabled:
204204
- name: baz
205205
pluginConfig:
206+
- name: InterPodAffinity
207+
args:
208+
hardPodAffinityWeight: 2
206209
- name: foo
207210
args:
208211
bar: baz
@@ -543,6 +546,12 @@ profiles:
543546
},
544547
},
545548
PluginConfig: []kubeschedulerconfig.PluginConfig{
549+
{
550+
Name: "InterPodAffinity",
551+
Args: &kubeschedulerconfig.InterPodAffinityArgs{
552+
HardPodAffinityWeight: 2,
553+
},
554+
},
546555
{
547556
Name: "foo",
548557
Args: &runtime.Unknown{
@@ -670,9 +679,7 @@ profiles:
670679
PluginConfig: []kubeschedulerconfig.PluginConfig{
671680
{
672681
Name: "InterPodAffinity",
673-
Args: &runtime.Unknown{
674-
Raw: []byte(`{"hardPodAffinityWeight":5}`),
675-
},
682+
Args: &kubeschedulerconfig.InterPodAffinityArgs{HardPodAffinityWeight: 5},
676683
},
677684
},
678685
},

pkg/scheduler/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ go_library(
4545
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
4646
"//staging/src/k8s.io/client-go/listers/policy/v1beta1:go_default_library",
4747
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
48-
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
4948
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
5049
"//vendor/k8s.io/klog:go_default_library",
5150
],

pkg/scheduler/apis/config/testing/compatibility_test.go

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
v1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
"k8s.io/apimachinery/pkg/runtime"
2928
utilfeature "k8s.io/apiserver/pkg/util/feature"
3029
"k8s.io/client-go/informers"
3130
"k8s.io/client-go/kubernetes/fake"
@@ -1598,90 +1597,58 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
15981597
pluginConfig: []config.PluginConfig{
15991598
{
16001599
Name: "NodeResourcesFit",
1601-
Args: &runtime.Unknown{
1602-
Raw: []byte(`{
1603-
"ignoredResources": [
1604-
"foo",
1605-
"bar"
1606-
]
1607-
}`),
1600+
Args: &config.NodeResourcesFitArgs{
1601+
IgnoredResources: []string{"foo", "bar"},
16081602
},
16091603
},
16101604
{
16111605
Name: "PodTopologySpread",
1612-
Args: &runtime.Unknown{
1613-
Raw: []byte(`{
1614-
"defaultConstraints": [
1615-
{
1616-
"maxSkew": 1,
1617-
"topologyKey": "foo",
1618-
"whenUnsatisfiable": "DoNotSchedule"
1619-
},
1620-
{
1621-
"maxSkew": 10,
1622-
"topologyKey": "bar",
1623-
"whenUnsatisfiable": "ScheduleAnyway"
1624-
}
1625-
]
1626-
}`),
1606+
Args: &config.PodTopologySpreadArgs{
1607+
DefaultConstraints: []v1.TopologySpreadConstraint{
1608+
{
1609+
MaxSkew: 1,
1610+
TopologyKey: "foo",
1611+
WhenUnsatisfiable: v1.DoNotSchedule,
1612+
},
1613+
{
1614+
MaxSkew: 10,
1615+
TopologyKey: "bar",
1616+
WhenUnsatisfiable: v1.ScheduleAnyway,
1617+
},
1618+
},
16271619
},
16281620
},
16291621
{
16301622
Name: "RequestedToCapacityRatio",
1631-
Args: &runtime.Unknown{
1632-
Raw: []byte(`{
1633-
"shape":[
1634-
"Utilization": 5,
1635-
"Score": 5
1636-
],
1637-
"resources":[
1638-
"Name": "cpu",
1639-
"Weight": 10
1640-
]
1641-
}`),
1623+
Args: &config.RequestedToCapacityRatioArgs{
1624+
Shape: []config.UtilizationShapePoint{
1625+
{Utilization: 5, Score: 5},
1626+
},
1627+
Resources: []config.ResourceSpec{
1628+
{Name: "cpu", Weight: 10},
1629+
},
16421630
},
16431631
},
16441632
{
16451633
Name: "InterPodAffinity",
1646-
Args: &runtime.Unknown{
1647-
Raw: []byte(`{
1648-
"HardPodAffinityWeight": 100
1649-
}`),
1634+
Args: &config.InterPodAffinityArgs{
1635+
HardPodAffinityWeight: 100,
16501636
},
16511637
},
16521638
{
16531639
Name: "NodeLabel",
1654-
Args: &runtime.Unknown{
1655-
Raw: []byte(`{
1656-
"presentLabels": [
1657-
"foo",
1658-
"bar"
1659-
],
1660-
"absentLabels": [
1661-
"apple"
1662-
],
1663-
"presentLabelsPreference": [
1664-
"dog"
1665-
],
1666-
"absentLabelsPreference": [
1667-
"cat"
1668-
]
1669-
}`),
1640+
Args: &config.NodeLabelArgs{
1641+
PresentLabels: []string{"foo", "bar"},
1642+
AbsentLabels: []string{"apple"},
1643+
PresentLabelsPreference: []string{"dog"},
1644+
AbsentLabelsPreference: []string{"cat"},
16701645
},
16711646
},
16721647
{
16731648
Name: "ServiceAffinity",
1674-
Args: &runtime.Unknown{
1675-
Raw: []byte(`{
1676-
affinityLabels: [
1677-
"foo",
1678-
"bar"
1679-
],
1680-
antiAffinityLabelsPreference: [
1681-
"disk",
1682-
"flash"
1683-
]
1684-
}`),
1649+
Args: &config.ServiceAffinityArgs{
1650+
AffinityLabels: []string{"foo", "bar"},
1651+
AntiAffinityLabelsPreference: []string{"disk", "flash"},
16851652
},
16861653
},
16871654
},

pkg/scheduler/factory.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
policylisters "k8s.io/client-go/listers/policy/v1beta1"
4141
"k8s.io/client-go/tools/cache"
4242
"k8s.io/klog"
43-
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
4443
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
4544
kubefeatures "k8s.io/kubernetes/pkg/features"
4645
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
@@ -162,12 +161,13 @@ func (c *Configurator) create() (*Scheduler, error) {
162161
if len(ignoredExtendedResources) > 0 {
163162
for i := range c.profiles {
164163
prof := &c.profiles[i]
165-
prof.PluginConfig = append(prof.PluginConfig,
166-
frameworkplugins.NewPluginConfig(
167-
noderesources.FitName,
168-
schedulerv1alpha2.NodeResourcesFitArgs{IgnoredResources: ignoredExtendedResources},
169-
),
170-
)
164+
pc := schedulerapi.PluginConfig{
165+
Name: noderesources.FitName,
166+
Args: &schedulerapi.NodeResourcesFitArgs{
167+
IgnoredResources: ignoredExtendedResources,
168+
},
169+
}
170+
prof.PluginConfig = append(prof.PluginConfig, pc)
171171
}
172172
}
173173

@@ -280,9 +280,8 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler,
280280
// HardPodAffinitySymmetricWeight in the policy config takes precedence over
281281
// CLI configuration.
282282
if policy.HardPodAffinitySymmetricWeight != 0 {
283-
v := policy.HardPodAffinitySymmetricWeight
284-
args.InterPodAffinityArgs = &schedulerv1alpha2.InterPodAffinityArgs{
285-
HardPodAffinityWeight: &v,
283+
args.InterPodAffinityArgs = &schedulerapi.InterPodAffinityArgs{
284+
HardPodAffinityWeight: policy.HardPodAffinitySymmetricWeight,
286285
}
287286
}
288287

pkg/scheduler/factory_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package scheduler
1818

1919
import (
2020
"context"
21-
"encoding/json"
2221
"errors"
2322
"reflect"
2423
"strings"
@@ -161,19 +160,27 @@ func TestCreateFromConfig(t *testing.T) {
161160
}
162161

163162
// Verify that node label predicate/priority are converted to framework plugins.
164-
wantArgs := `{"Name":"NodeLabel","Args":{"presentLabels":["zone"],"absentLabels":["foo"],"presentLabelsPreference":["l1"],"absentLabelsPreference":["l2"]}}`
163+
var wantArgs runtime.Object = &schedulerapi.NodeLabelArgs{
164+
PresentLabels: []string{"zone"},
165+
AbsentLabels: []string{"foo"},
166+
PresentLabelsPreference: []string{"l1"},
167+
AbsentLabelsPreference: []string{"l2"},
168+
}
165169
verifyPluginConvertion(t, nodelabel.Name, []string{"FilterPlugin", "ScorePlugin"}, prof, &factory.profiles[0], 6, wantArgs)
166170
// Verify that service affinity custom predicate/priority is converted to framework plugin.
167-
wantArgs = `{"Name":"ServiceAffinity","Args":{"affinityLabels":["zone","foo"],"antiAffinityLabelsPreference":["rack","zone"]}}`
171+
wantArgs = &schedulerapi.ServiceAffinityArgs{
172+
AffinityLabels: []string{"zone", "foo"},
173+
AntiAffinityLabelsPreference: []string{"rack", "zone"},
174+
}
168175
verifyPluginConvertion(t, serviceaffinity.Name, []string{"FilterPlugin", "ScorePlugin"}, prof, &factory.profiles[0], 6, wantArgs)
169176
// TODO(#87703): Verify all plugin configs.
170177
})
171178
}
172179

173180
}
174181

175-
func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, prof *profile.Profile, cfg *schedulerapi.KubeSchedulerProfile, wantWeight int32, wantArgs string) {
176-
for _, extensionPoint := range extentionPoints {
182+
func verifyPluginConvertion(t *testing.T, name string, extensionPoints []string, prof *profile.Profile, cfg *schedulerapi.KubeSchedulerProfile, wantWeight int32, wantArgs runtime.Object) {
183+
for _, extensionPoint := range extensionPoints {
177184
plugin, ok := findPlugin(name, extensionPoint, prof)
178185
if !ok {
179186
t.Fatalf("%q plugin does not exist in framework.", name)
@@ -185,12 +192,8 @@ func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string,
185192
}
186193
// Verify that the policy config is converted to plugin config.
187194
pluginConfig := findPluginConfig(name, cfg)
188-
encoding, err := json.Marshal(pluginConfig)
189-
if err != nil {
190-
t.Errorf("Failed to marshal %+v: %v", pluginConfig, err)
191-
}
192-
if string(encoding) != wantArgs {
193-
t.Errorf("Config for %v plugin mismatch. got: %v, want: %v", name, string(encoding), wantArgs)
195+
if diff := cmp.Diff(wantArgs, pluginConfig.Args); diff != "" {
196+
t.Errorf("Config for %v plugin mismatch (-want,+got):\n%s", name, diff)
194197
}
195198
}
196199
}
@@ -250,7 +253,7 @@ func TestCreateFromConfigWithHardPodAffinitySymmetricWeight(t *testing.T) {
250253
for _, cfg := range factory.profiles[0].PluginConfig {
251254
if cfg.Name == interpodaffinity.Name {
252255
foundAffinityCfg = true
253-
wantArgs := &runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":10}`)}
256+
wantArgs := &schedulerapi.InterPodAffinityArgs{HardPodAffinityWeight: 10}
254257

255258
if diff := cmp.Diff(wantArgs, cfg.Args); diff != "" {
256259
t.Errorf("wrong InterPodAffinity args (-want, +got): %s", diff)

pkg/scheduler/framework/plugins/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ go_library(
3131
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
3232
"//pkg/scheduler/framework/plugins/volumezone:go_default_library",
3333
"//pkg/scheduler/framework/v1alpha1:go_default_library",
34-
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
3534
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
3635
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
37-
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
3836
"//vendor/k8s.io/klog:go_default_library",
3937
],
4038
)

pkg/scheduler/framework/plugins/interpodaffinity/BUILD

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity",
1111
visibility = ["//visibility:public"],
1212
deps = [
13+
"//pkg/scheduler/apis/config:go_default_library",
1314
"//pkg/scheduler/framework/v1alpha1:go_default_library",
1415
"//pkg/scheduler/internal/parallelize:go_default_library",
1516
"//pkg/scheduler/util:go_default_library",
@@ -19,9 +20,7 @@ go_library(
1920
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
2021
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
2122
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
22-
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
2323
"//vendor/k8s.io/klog:go_default_library",
24-
"//vendor/k8s.io/utils/pointer:go_default_library",
2524
],
2625
)
2726

@@ -33,13 +32,11 @@ go_test(
3332
],
3433
embed = [":go_default_library"],
3534
deps = [
35+
"//pkg/scheduler/apis/config:go_default_library",
3636
"//pkg/scheduler/framework/v1alpha1:go_default_library",
3737
"//pkg/scheduler/internal/cache:go_default_library",
3838
"//staging/src/k8s.io/api/core/v1:go_default_library",
3939
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
40-
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
41-
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
42-
"//vendor/k8s.io/utils/pointer:go_default_library",
4340
],
4441
)
4542

0 commit comments

Comments
 (0)