From fcc73d355d0a4324397996abff37ba9877a5ebd3 Mon Sep 17 00:00:00 2001 From: Haoran Wang Date: Mon, 27 Mar 2017 11:05:26 +0800 Subject: [PATCH 1/2] Multiple scheduler leader election support --- hack/verify-flags/known-flags.txt | 2 ++ pkg/apis/componentconfig/types.go | 12 ++++++++++++ pkg/apis/componentconfig/v1alpha1/defaults.go | 6 ++++++ pkg/apis/componentconfig/v1alpha1/types.go | 12 ++++++++++++ plugin/cmd/kube-scheduler/app/options/options.go | 2 ++ plugin/cmd/kube-scheduler/app/server.go | 4 ++-- 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/hack/verify-flags/known-flags.txt b/hack/verify-flags/known-flags.txt index c36f7e09e32..1d83bd6179c 100644 --- a/hack/verify-flags/known-flags.txt +++ b/hack/verify-flags/known-flags.txt @@ -702,5 +702,7 @@ windows-line-endings www-prefix zone-id zone-name +lock-object-name +lock-object-namespace horizontal-pod-autoscaler-use-rest-clients diff --git a/pkg/apis/componentconfig/types.go b/pkg/apis/componentconfig/types.go index 3df5a2e1233..78abfe24611 100644 --- a/pkg/apis/componentconfig/types.go +++ b/pkg/apis/componentconfig/types.go @@ -595,6 +595,10 @@ type KubeSchedulerConfiguration struct { FailureDomains string // leaderElection defines the configuration of leader election client. LeaderElection LeaderElectionConfiguration + // LockObjectNamespace defines the namespace of the lock object + LockObjectNamespace string + // LockObjectName defines the lock object name + LockObjectName string } // LeaderElectionConfiguration defines the configuration of leader election @@ -904,3 +908,11 @@ func (m *ConfigurationMap) Set(value string) error { func (*ConfigurationMap) Type() string { return "mapStringString" } + +const ( + // "kube-system" is the default scheduler lock object namespace + SchedulerDefaultLockObjectNamespace string = "kube-system" + + // "kube-scheduler" is the default scheduler lock object name + SchedulerDefaultLockObjectName = "kube-scheduler" +) diff --git a/pkg/apis/componentconfig/v1alpha1/defaults.go b/pkg/apis/componentconfig/v1alpha1/defaults.go index 63d908d56fb..bb99f8f3cd9 100644 --- a/pkg/apis/componentconfig/v1alpha1/defaults.go +++ b/pkg/apis/componentconfig/v1alpha1/defaults.go @@ -158,6 +158,12 @@ func SetDefaults_KubeSchedulerConfiguration(obj *KubeSchedulerConfiguration) { if obj.FailureDomains == "" { obj.FailureDomains = api.DefaultFailureDomains } + if obj.LockObjectNamespace == "" { + obj.LockObjectNamespace = SchedulerDefaultLockObjectNamespace + } + if obj.LockObjectName == "" { + obj.LockObjectName = SchedulerDefaultLockObjectName + } } func SetDefaults_LeaderElectionConfiguration(obj *LeaderElectionConfiguration) { diff --git a/pkg/apis/componentconfig/v1alpha1/types.go b/pkg/apis/componentconfig/v1alpha1/types.go index 0b90fcd69b1..7ef07c29fb8 100644 --- a/pkg/apis/componentconfig/v1alpha1/types.go +++ b/pkg/apis/componentconfig/v1alpha1/types.go @@ -130,6 +130,10 @@ type KubeSchedulerConfiguration struct { FailureDomains string `json:"failureDomains"` // leaderElection defines the configuration of leader election client. LeaderElection LeaderElectionConfiguration `json:"leaderElection"` + // LockObjectNamespace defines the namespace of the lock object + LockObjectNamespace string `json:"lockObjectNamespace"` + // LockObjectName defines the lock object name + LockObjectName string `json:"lockObjectName"` } // HairpinMode denotes how the kubelet should configure networking to handle @@ -600,3 +604,11 @@ type KubeletAnonymousAuthentication struct { // Anonymous requests have a username of system:anonymous, and a group name of system:unauthenticated. Enabled *bool `json:"enabled"` } + +const ( + // "kube-system" is the default scheduler lock object namespace + SchedulerDefaultLockObjectNamespace string = "kube-system" + + // "kube-scheduler" is the default scheduler lock object name + SchedulerDefaultLockObjectName = "kube-scheduler" +) diff --git a/plugin/cmd/kube-scheduler/app/options/options.go b/plugin/cmd/kube-scheduler/app/options/options.go index 1d84938553a..eb13671f49c 100644 --- a/plugin/cmd/kube-scheduler/app/options/options.go +++ b/plugin/cmd/kube-scheduler/app/options/options.go @@ -72,6 +72,8 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) { fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") fs.Int32Var(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") fs.StringVar(&s.SchedulerName, "scheduler-name", s.SchedulerName, "Name of the scheduler, used to select which pods will be processed by this scheduler, based on pod's \"spec.SchedulerName\".") + fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object.") + fs.StringVar(&s.LockObjectName, "lock-object-name", s.LockObjectName, "Define the name of the lock object.") fs.IntVar(&s.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", api.DefaultHardPodAffinitySymmetricWeight, "RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule corresponding "+ "to every RequiredDuringScheduling affinity rule. --hard-pod-affinity-symmetric-weight represents the weight of implicit PreferredDuringScheduling affinity rule.") diff --git a/plugin/cmd/kube-scheduler/app/server.go b/plugin/cmd/kube-scheduler/app/server.go index 78d4f6d5ee4..fd70e7cf22e 100644 --- a/plugin/cmd/kube-scheduler/app/server.go +++ b/plugin/cmd/kube-scheduler/app/server.go @@ -113,8 +113,8 @@ func Run(s *options.SchedulerServer) error { // TODO: enable other lock types rl := &resourcelock.EndpointsLock{ EndpointsMeta: metav1.ObjectMeta{ - Namespace: "kube-system", - Name: "kube-scheduler", + Namespace: s.LockObjectNamespace, + Name: s.LockObjectName, }, Client: kubecli, LockConfig: resourcelock.ResourceLockConfig{ From 251abaa72f31c1c514df361c33f40e6f1ec9a6c1 Mon Sep 17 00:00:00 2001 From: Haoran Wang Date: Wed, 5 Apr 2017 15:19:13 +0800 Subject: [PATCH 2/2] generated --- .../v1alpha1/zz_generated.conversion.go | 4 ++++ pkg/generated/openapi/zz_generated.openapi.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go index 8cf622c8126..83ae17ffe9b 100644 --- a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go @@ -137,6 +137,8 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_componentconfig_KubeSche if err := Convert_v1alpha1_LeaderElectionConfiguration_To_componentconfig_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } + out.LockObjectNamespace = in.LockObjectNamespace + out.LockObjectName = in.LockObjectName return nil } @@ -162,6 +164,8 @@ func autoConvert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSche if err := Convert_componentconfig_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } + out.LockObjectNamespace = in.LockObjectNamespace + out.LockObjectName = in.LockObjectName return nil } diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 3f7ea937ae8..6f9376dd134 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -12878,8 +12878,22 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope Ref: ref("k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1.LeaderElectionConfiguration"), }, }, + "lockObjectNamespace": { + SchemaProps: spec.SchemaProps{ + Description: "LockObjectNamespace defines the namespace of the lock object", + Type: []string{"string"}, + Format: "", + }, + }, + "lockObjectName": { + SchemaProps: spec.SchemaProps{ + Description: "LockObjectName defines the lock object name", + Type: []string{"string"}, + Format: "", + }, + }, }, - Required: []string{"port", "address", "algorithmProvider", "policyConfigFile", "enableProfiling", "enableContentionProfiling", "contentType", "kubeAPIQPS", "kubeAPIBurst", "schedulerName", "hardPodAffinitySymmetricWeight", "failureDomains", "leaderElection"}, + Required: []string{"port", "address", "algorithmProvider", "policyConfigFile", "enableProfiling", "enableContentionProfiling", "contentType", "kubeAPIQPS", "kubeAPIBurst", "schedulerName", "hardPodAffinitySymmetricWeight", "failureDomains", "leaderElection", "lockObjectNamespace", "lockObjectName"}, }, }, Dependencies: []string{