From 203af5c4f8345ef034327b881b1239e9debadfb1 Mon Sep 17 00:00:00 2001 From: Paul Morie Date: Wed, 7 Jun 2017 14:59:02 -0400 Subject: [PATCH] Add leader election namespace configuration (#920) --- .../controller-manager-deployment.yaml | 8 +++++++ charts/catalog/values.yaml | 3 +++ .../app/controller_manager.go | 4 +++- cmd/controller-manager/app/options/options.go | 23 +++++++++++-------- pkg/apis/componentconfig/types.go | 4 ++++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/charts/catalog/templates/controller-manager-deployment.yaml b/charts/catalog/templates/controller-manager-deployment.yaml index c68684e486f6..24066af4a9b3 100644 --- a/charts/catalog/templates/controller-manager-deployment.yaml +++ b/charts/catalog/templates/controller-manager-deployment.yaml @@ -31,9 +31,17 @@ spec: limits: cpu: 100m memory: 30Mi + env: + - name: K8S_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace args: - --port - "8080" + {{ if .Values.controllerManager.leaderElectionNamespace.activated -}} + - "--leader-election-namespace=$(K8S_NAMESPACE)" + {{- end }} {{ if .Values.controllerManager.profiling.disabled -}} - "--profiling=false" {{- end}} diff --git a/charts/catalog/values.yaml b/charts/catalog/values.yaml index 887931aecf00..0b083810a988 100644 --- a/charts/catalog/values.yaml +++ b/charts/catalog/values.yaml @@ -75,4 +75,7 @@ controllerManager: disabled: false # Enables lock contention profiling, if profiling is enabled. contentionProfiling: false + leaderElectionNamespace: + # Whether the controller has option to set leader election namespace. + activated: false useAggregator: false diff --git a/cmd/controller-manager/app/controller_manager.go b/cmd/controller-manager/app/controller_manager.go index ec7665229cfd..97c7cad8159c 100644 --- a/cmd/controller-manager/app/controller_manager.go +++ b/cmd/controller-manager/app/controller_manager.go @@ -208,10 +208,12 @@ func Run(controllerManagerOptions *options.ControllerManagerServer) error { return err } + glog.V(5).Infof("Using namespace %v for leader election lock", controllerManagerOptions.LeaderElectionNamespace) + // Lock required for leader election rl := resourcelock.EndpointsLock{ EndpointsMeta: metav1.ObjectMeta{ - Namespace: "kube-system", + Namespace: controllerManagerOptions.LeaderElectionNamespace, Name: "service-catalog-controller-manager", }, Client: leaderElectionClient, diff --git a/cmd/controller-manager/app/options/options.go b/cmd/controller-manager/app/options/options.go index fce70d4208c3..2977f67fe5e2 100644 --- a/cmd/controller-manager/app/options/options.go +++ b/cmd/controller-manager/app/options/options.go @@ -36,15 +36,18 @@ type ControllerManagerServer struct { componentconfig.ControllerManagerConfiguration } -const defaultResyncInterval = 5 * time.Minute -const defaultBrokerRelistInterval = 24 * time.Hour -const defaultContentType = "application/json" -const defaultBindAddress = "0.0.0.0" -const defaultPort = 10000 -const defaultK8sKubeconfigPath = "./kubeconfig" -const defaultServiceCatalogKubeconfigPath = "./service-catalog-kubeconfig" -const defaultOSBAPIContextProfile = true -const defaultConcurrentSyncs = 5 +const ( + defaultResyncInterval = 5 * time.Minute + defaultBrokerRelistInterval = 24 * time.Hour + defaultContentType = "application/json" + defaultBindAddress = "0.0.0.0" + defaultPort = 10000 + defaultK8sKubeconfigPath = "./kubeconfig" + defaultServiceCatalogKubeconfigPath = "./service-catalog-kubeconfig" + defaultOSBAPIContextProfile = true + defaultConcurrentSyncs = 5 + defaultLeaderElectionNamespace = "kube-system" +) // NewControllerManagerServer creates a new ControllerManagerServer with a // default config. @@ -61,6 +64,7 @@ func NewControllerManagerServer() *ControllerManagerServer { OSBAPIContextProfile: defaultOSBAPIContextProfile, ConcurrentSyncs: defaultConcurrentSyncs, LeaderElection: leaderelection.DefaultLeaderElectionConfiguration(), + LeaderElectionNamespace: defaultLeaderElectionNamespace, EnableProfiling: true, EnableContentionProfiling: false, }, @@ -84,4 +88,5 @@ func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, "Enable profiling via web interface host:port/debug/pprof/") fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling, "Enable lock contention profiling, if profiling is enabled") leaderelection.BindFlags(&s.LeaderElection, fs) + fs.StringVar(&s.LeaderElectionNamespace, "leader-election-namespace", s.LeaderElectionNamespace, "Namespace to use for leader election lock") } diff --git a/pkg/apis/componentconfig/types.go b/pkg/apis/componentconfig/types.go index f7cab47a33d6..e89173764691 100644 --- a/pkg/apis/componentconfig/types.go +++ b/pkg/apis/componentconfig/types.go @@ -75,6 +75,10 @@ type ControllerManagerConfiguration struct { // leaderElection defines the configuration of leader election client. LeaderElection componentconfig.LeaderElectionConfiguration + // LeaderElectionNamespace is the namespace to use for the leader election + // lock. + LeaderElectionNamespace string + // enableProfiling enables profiling via web interface host:port/debug/pprof/ EnableProfiling bool