Skip to content

Commit

Permalink
Add leader election namespace configuration (openshift#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie authored and jpeeler committed Jun 7, 2017
1 parent 5831502 commit 203af5c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
8 changes: 8 additions & 0 deletions charts/catalog/templates/controller-manager-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
3 changes: 3 additions & 0 deletions charts/catalog/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion cmd/controller-manager/app/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 14 additions & 9 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -61,6 +64,7 @@ func NewControllerManagerServer() *ControllerManagerServer {
OSBAPIContextProfile: defaultOSBAPIContextProfile,
ConcurrentSyncs: defaultConcurrentSyncs,
LeaderElection: leaderelection.DefaultLeaderElectionConfiguration(),
LeaderElectionNamespace: defaultLeaderElectionNamespace,
EnableProfiling: true,
EnableContentionProfiling: false,
},
Expand All @@ -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")
}
4 changes: 4 additions & 0 deletions pkg/apis/componentconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 203af5c

Please sign in to comment.