Skip to content

Commit 6645a73

Browse files
committed
feat(chart): VPA Updater leaderElection
Signed-off-by: phuhung273 <[email protected]>
1 parent 65d6e37 commit 6645a73

File tree

6 files changed

+52
-12
lines changed

6 files changed

+52
-12
lines changed

vertical-pod-autoscaler/charts/vertical-pod-autoscaler/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ The Vertical Pod Autoscaler (VPA) automatically adjusts the CPU and memory resou
9797
| updater.image.pullPolicy | string | `"IfNotPresent"` | |
9898
| updater.image.repository | string | `"registry.k8s.io/autoscaling/vpa-updater"` | |
9999
| updater.image.tag | string | `nil` | |
100+
| updater.leaderElection.enabled | string | `nil` | |
101+
| updater.leaderElection.leaseDuration | string | `"15s"` | |
102+
| updater.leaderElection.renewDeadline | string | `"10s"` | |
103+
| updater.leaderElection.resourceName | string | `"vpa-updater-lease"` | |
104+
| updater.leaderElection.resourceNamespace | string | `""` | |
105+
| updater.leaderElection.retryPeriod | string | `"2s"` | |
100106
| updater.podAnnotations | object | `{}` | |
101107
| updater.podLabels | object | `{}` | |
102-
| updater.replicas | int | `1` | |
108+
| updater.replicas | int | `2` | |
103109
| updater.serviceAccount.annotations | object | `{}` | |
104110
| updater.serviceAccount.create | bool | `true` | |
105111
| updater.serviceAccount.labels | object | `{}` | |

vertical-pod-autoscaler/charts/vertical-pod-autoscaler/templates/_helpers.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ app.kubernetes.io/component: updater
9696
{{- printf "%s:%s" .Values.updater.image.repository (default .Chart.AppVersion .Values.updater.image.tag) }}
9797
{{- end }}
9898

99+
{{- define "vertical-pod-autoscaler.updater.leaderElectionEnabled" -}}
100+
{{- if and (eq .Values.updater.leaderElection.enabled nil) (gt (int .Values.updater.replicas) 1) -}}
101+
true
102+
{{- else if .Values.updater.leaderElection.enabled -}}
103+
true
104+
{{- else -}}
105+
false
106+
{{- end -}}
107+
{{- end -}}
108+
99109

100110
{{/*
101111
Create the name of the namespace to use

vertical-pod-autoscaler/charts/vertical-pod-autoscaler/templates/updater-deployment.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ spec:
4040
valueFrom:
4141
fieldRef:
4242
fieldPath: metadata.namespace
43+
args:
44+
- --v=4
45+
- --stderrthreshold=info
46+
{{- if eq (include "vertical-pod-autoscaler.updater.leaderElectionEnabled" .) "true" }}
47+
- --leader-elect=true
48+
- --leader-elect-resource-namespace={{ .Values.updater.leaderElection.resourceNamespace | default .Release.Namespace }}
49+
- --leader-elect-resource-name={{ .Values.updater.leaderElection.resourceName }}
50+
- --leader-elect-lease-duration={{ .Values.updater.leaderElection.leaseDuration }}
51+
- --leader-elect-renew-deadline={{ .Values.updater.leaderElection.renewDeadline }}
52+
- --leader-elect-retry-period={{ .Values.updater.leaderElection.retryPeriod }}
53+
{{- end }}
4354
ports:
4455
- name: prometheus
4556
containerPort: 8943
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
{{- if and (.Values.updater.enabled) .Values.updater.serviceAccount.create -}}
1+
{{- if and .Values.updater.enabled .Values.rbac.create -}}
2+
{{- if eq (include "vertical-pod-autoscaler.updater.leaderElectionEnabled" .) "true" }}
23
apiVersion: rbac.authorization.k8s.io/v1
34
kind: Role
45
metadata:
56
name: {{ include "vertical-pod-autoscaler.updater.fullname" . }}-leader-locking
67
namespace: {{ .Release.Namespace }}
78
labels:
89
{{- include "vertical-pod-autoscaler.updater.labels" . | nindent 4 }}
9-
{{- with .Values.updater.serviceAccount.labels }}
10-
{{- toYaml . | nindent 4 }}
11-
{{- end }}
12-
{{- with .Values.updater.serviceAccount.annotations }}
13-
annotations:
14-
{{- toYaml . | nindent 4 }}
15-
{{- end }}
1610
rules:
1711
- apiGroups:
1812
- "coordination.k8s.io"
@@ -23,11 +17,12 @@ rules:
2317
- apiGroups:
2418
- "coordination.k8s.io"
2519
resourceNames:
26-
- vpa-updater
20+
- {{ .Values.updater.leaderElection.resourceName }}
2721
resources:
2822
- leases
2923
verbs:
3024
- get
3125
- watch
3226
- update
3327
{{- end -}}
28+
{{- end -}}

vertical-pod-autoscaler/charts/vertical-pod-autoscaler/templates/updater-rolebinding.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- if and (.Values.updater.enabled) .Values.rbac.create -}}
1+
{{- if and .Values.updater.enabled .Values.rbac.create -}}
2+
{{- if eq (include "vertical-pod-autoscaler.updater.leaderElectionEnabled" .) "true" }}
23
apiVersion: rbac.authorization.k8s.io/v1
34
kind: RoleBinding
45
metadata:
@@ -13,3 +14,4 @@ subjects:
1314
name: {{ include "vertical-pod-autoscaler.updater.fullname" . }}
1415
namespace: {{ .Release.Namespace }}
1516
{{- end -}}
17+
{{- end -}}

vertical-pod-autoscaler/charts/vertical-pod-autoscaler/values.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ updater:
191191
pullPolicy: IfNotPresent
192192

193193
# Number of Updater replicas to create.
194-
replicas: 1
194+
replicas: 2
195195

196196
# Labels to add to the Updater pod.
197197
podLabels: {}
@@ -205,3 +205,19 @@ updater:
205205
labels: {}
206206
# Annotations to add to the Updater service account.
207207
annotations: {}
208+
209+
# Leader election configuration for the Updater.
210+
# When running multiple replicas, leader election ensures only one instance is actively processing.
211+
leaderElection:
212+
# Enable leader election. If not set (null), automatically enabled when replicas > 1
213+
enabled:
214+
# Namespace for the lease resource. Defaults to Release.Namespace if not set.
215+
resourceNamespace: ""
216+
# Name of the lease resource.
217+
resourceName: vpa-updater-lease
218+
# Duration that non-leader candidates will wait after observing a leadership renewal.
219+
leaseDuration: 15s
220+
# Interval between attempts by the acting master to renew a leadership slot.
221+
renewDeadline: 10s
222+
# Duration the clients should wait between attempting acquisition and renewal of a leadership.
223+
retryPeriod: 2s

0 commit comments

Comments
 (0)