Skip to content

Commit 6449e45

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 e9b6859 commit 6449e45

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

templates/cmd/controller/main.go.tpl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ resources across service controller. */ -}}
3737
"github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/pkg/version"
3838
)
3939

40+
const (
41+
ackSystemNamespace = "ack-system"
42+
)
43+
4044
var (
4145
awsServiceAPIGroup = "{{ .APIGroup }}"
4246
awsServiceAlias = "{{ .ServicePackageName }}"
@@ -87,13 +91,14 @@ func main() {
8791
}
8892

8993
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,
94+
Scheme: scheme,
95+
Port: port,
96+
Host: host,
97+
MetricsBindAddress: ackCfg.MetricsAddr,
98+
LeaderElection: ackCfg.EnableLeaderElection,
99+
LeaderElectionID: awsServiceAPIGroup,
100+
Namespace: ackCfg.WatchNamespace,
101+
LeaderElectionNamespace: ackSystemNamespace,
97102
})
98103
if err != nil {
99104
setupLog.Error(

templates/helm/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ spec:
5858
- "$(ACK_WATCH_NAMESPACE)"
5959
- --deletion-policy
6060
- "$(DELETION_POLICY)"
61+
- --enable-leader-election
62+
- "$(ENABLE_LEADER_ELECTION)"
6163
{{- if gt .Values.reconcile.defaultResyncPeriod 0.0 }}
6264
- --reconcile-default-resync-seconds
6365
- "$(RECONCILE_DEFAULT_RESYNC_SECONDS)"
@@ -87,6 +89,8 @@ spec:
8789
value: {{ include "watch-namespace" . }}
8890
- name: DELETION_POLICY
8991
value: {{ .Values.deletionPolicy }}
92+
- name: ENABLED_LEADER_ELECTION
93+
value: {{ .Values.leaderElection.enabled | quote }}
9094
- name: ACK_ENABLE_DEVELOPMENT_LOGGING
9195
value: {{ .Values.log.enable_development_logging | quote }}
9296
- 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@ 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+
enabled: false

0 commit comments

Comments
 (0)