From 7b108d8ee1905e3beaf9b15207e61a351ddd05dc Mon Sep 17 00:00:00 2001 From: kerthcet Date: Mon, 19 Feb 2024 20:45:48 +0800 Subject: [PATCH 1/2] Add testcase covering unknown plugin config Signed-off-by: kerthcet --- pkg/scheduler/apis/config/v1/defaults_test.go | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/scheduler/apis/config/v1/defaults_test.go b/pkg/scheduler/apis/config/v1/defaults_test.go index 354737817c1..deecebc4c1d 100644 --- a/pkg/scheduler/apis/config/v1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1/defaults_test.go @@ -117,6 +117,9 @@ var pluginConfigs = []configv1.PluginConfig{ func TestSchedulerDefaults(t *testing.T) { enable := true + unknownPluginConfigs := append([]configv1.PluginConfig{}, pluginConfigs...) + unknownPluginConfigs[0].Args = runtime.RawExtension{Object: &runtime.Unknown{}} + tests := []struct { name string config *configv1.KubeSchedulerConfiguration @@ -599,7 +602,49 @@ func TestSchedulerDefaults(t *testing.T) { }, }, }, + { + name: "unknown plugin config", + config: &configv1.KubeSchedulerConfiguration{ + Profiles: []configv1.KubeSchedulerProfile{ + { + PluginConfig: unknownPluginConfigs, + }, + }, + }, + expected: &configv1.KubeSchedulerConfiguration{ + Parallelism: ptr.To[int32](16), + DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: &enable, + EnableContentionProfiling: &enable, + }, + LeaderElection: componentbaseconfig.LeaderElectionConfiguration{ + LeaderElect: ptr.To(true), + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, + ResourceLock: "leases", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + PercentageOfNodesToScore: ptr.To[int32](config.DefaultPercentageOfNodesToScore), + PodInitialBackoffSeconds: ptr.To[int64](1), + PodMaxBackoffSeconds: ptr.To[int64](10), + Profiles: []configv1.KubeSchedulerProfile{ + { + Plugins: getDefaultPlugins(), + PluginConfig: unknownPluginConfigs, + SchedulerName: ptr.To("default-scheduler"), + }, + }, + }, + }, } + for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { SetDefaults_KubeSchedulerConfiguration(tc.config) From 3c9c141d98088873b3d606b260bbcd6636718c59 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Mon, 19 Feb 2024 20:46:36 +0800 Subject: [PATCH 2/2] exchange the order of comparators Signed-off-by: kerthcet --- pkg/scheduler/apis/config/v1/defaults_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/scheduler/apis/config/v1/defaults_test.go b/pkg/scheduler/apis/config/v1/defaults_test.go index deecebc4c1d..cdfcc9a60a8 100644 --- a/pkg/scheduler/apis/config/v1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1/defaults_test.go @@ -845,7 +845,7 @@ func TestPluginArgsDefaults(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)() } scheme.Default(tc.in) - if diff := cmp.Diff(tc.in, tc.want); diff != "" { + if diff := cmp.Diff(tc.want, tc.in); diff != "" { t.Errorf("Got unexpected defaults (-want, +got):\n%s", diff) } })