Skip to content

Commit a6cf6df

Browse files
committed
Add missing leader election configuration to the contoller manager
ACK controllers use k8s-sigs/controller-runtime behind the scenes, which support leader election. This feature is not properly working due to a missing configuration `LeaderElectionNamespace` which is used by the manager to create `k8s.io/coordination` Lease objects. This patch sets the default `LeaderElectionNamespace` to `ack-system` and adds the capability of enabling leader election using helm values.
1 parent e9c5318 commit a6cf6df

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

templates/cmd/controller/main.go.tpl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ func main() {
8787
}
8888

8989
mgr, err := ctrlrt.NewManager(ctrlrt.GetConfigOrDie(), ctrlrt.Options{
90-
Scheme: scheme,
91-
Port: port,
92-
Host: host,
93-
MetricsBindAddress: ackCfg.MetricsAddr,
94-
LeaderElection: ackCfg.EnableLeaderElection,
95-
LeaderElectionID: awsServiceAPIGroup,
96-
Namespace: ackCfg.WatchNamespace,
90+
Scheme: scheme,
91+
Port: port,
92+
Host: host,
93+
MetricsBindAddress: ackCfg.MetricsAddr,
94+
LeaderElection: ackCfg.EnableLeaderElection,
95+
LeaderElectionID: awsServiceAPIGroup,
96+
Namespace: ackCfg.WatchNamespace,
97+
LeaderElectionNamespace: ackCfg.LeaderElectionNamespace,
9798
})
9899
if err != nil {
99100
setupLog.Error(

templates/config/controller/deployment.yaml.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
- "$(ACK_RESOURCE_TAGS)"
3737
- --watch-namespace
3838
- "$(ACK_WATCH_NAMESPACE)"
39+
- --enable-leader-election
40+
- "$(ENABLE_LEADER_ELECTION)"
41+
- --leader-election-namespace
42+
- "$(LEADER_ELECTION_NAMESPACE)"
3943
image: controller:latest
4044
name: controller
4145
ports:
@@ -65,6 +69,10 @@ spec:
6569
value: "info"
6670
- name: ACK_RESOURCE_TAGS
6771
value: "services.k8s.aws/controller-version=%CONTROLLER_SERVICE%-%CONTROLLER_VERSION%,services.k8s.aws/namespace=%K8S_NAMESPACE%"
72+
- name: ENABLED_LEADER_ELECTION
73+
value: "false"
74+
- name: LEADER_ELECTION_NAMESPACE
75+
value: ""
6876
securityContext:
6977
allowPrivilegeEscalation: false
7078
privileged: false

templates/helm/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ spec:
5858
- "$(ACK_WATCH_NAMESPACE)"
5959
- --deletion-policy
6060
- "$(DELETION_POLICY)"
61+
- --enable-leader-election
62+
- "$(ENABLE_LEADER_ELECTION)"
63+
- --leader-election-namespace
64+
- "$(LEADER_ELECTION_NAMESPACE)"
6165
{{- if gt .Values.reconcile.defaultResyncPeriod 0.0 }}
6266
- --reconcile-default-resync-seconds
6367
- "$(RECONCILE_DEFAULT_RESYNC_SECONDS)"
@@ -87,6 +91,10 @@ spec:
8791
value: {{ include "watch-namespace" . }}
8892
- name: DELETION_POLICY
8993
value: {{ .Values.deletionPolicy }}
94+
- name: ENABLED_LEADER_ELECTION
95+
value: {{ .Values.leaderElection.enabled | quote }}
96+
- name: LEADER_ELECTION_NAMESPACE
97+
value: {{ .Values.leaderElection.namespace | quote }}
9098
- name: ACK_ENABLE_DEVELOPMENT_LOGGING
9199
value: {{ .Values.log.enable_development_logging | quote }}
92100
- name: ACK_LOG_LEVEL

templates/helm/values.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@
231231
},
232232
"type": "object"
233233
},
234+
"leaderElection": {
235+
"description": "Parameter to configure the controller's leader election system.",
236+
"properties": {
237+
"enabled": {
238+
"type": "boolean"
239+
}
240+
},
241+
"type": "object"
242+
},
234243
"serviceAccount": {
235244
"description": "ServiceAccount settings",
236245
"properties": {

templates/helm/values.yaml.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,11 @@ serviceAccount:
121121
name: {{ .ServiceAccountName }}
122122
annotations: {}
123123
# eks.amazonaws.com/role-arn: arn:aws:iam::AWS_ACCOUNT_ID:role/IAM_ROLE_NAME
124+
125+
# leader election configurations
126+
leaderElection:
127+
# Enables controller leader election
128+
enabled: false
129+
# Sets the leader election namespace. By default it will try to use the namespace of
130+
# the service account mounted to the controller pod.
131+
namespace: ""

0 commit comments

Comments
 (0)