From d71c2a214abc5a16b236b6c2248abfcdbee25c3b Mon Sep 17 00:00:00 2001 From: "vitor.cassiano" Date: Wed, 15 May 2024 20:06:13 -0300 Subject: [PATCH] feat(argo-rollouts): Add hpa to handle controller scaling Signed-off-by: vitor.cassiano --- charts/argo-rollouts/templates/_helpers.tpl | 8 ++++ .../templates/controller/hpa.yaml | 41 +++++++++++++++++++ charts/argo-rollouts/values.yaml | 6 +++ 3 files changed, 55 insertions(+) create mode 100644 charts/argo-rollouts/templates/controller/hpa.yaml diff --git a/charts/argo-rollouts/templates/_helpers.tpl b/charts/argo-rollouts/templates/_helpers.tpl index 46ebaea5..bfacf4e2 100644 --- a/charts/argo-rollouts/templates/_helpers.tpl +++ b/charts/argo-rollouts/templates/_helpers.tpl @@ -109,3 +109,11 @@ Return the appropriate apiVersion for pod disruption budget {{- print "policy/v1" -}} {{- end -}} {{- end -}} + +{{/* +Expand the namespace of the release. +Allows overriding it for multi-namespace deployments in combined charts. +*/}} +{{- define "argo-rollouts.namespace" -}} +{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}} +{{- end }} diff --git a/charts/argo-rollouts/templates/controller/hpa.yaml b/charts/argo-rollouts/templates/controller/hpa.yaml new file mode 100644 index 00000000..9924754d --- /dev/null +++ b/charts/argo-rollouts/templates/controller/hpa.yaml @@ -0,0 +1,41 @@ +{{- if .Values.controller.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "argo-rollouts.fullname" . }} + namespace: {{ include "argo-rollouts.namespace" . }} + labels: + {{- include "argo-rollouts.labels" (dict "context" .) | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "argo-rollouts.fullname" . }} + minReplicas: {{ .Values.controller.autoscaling.minReplicas }} + maxReplicas: {{ .Values.controller.autoscaling.maxReplicas }} + metrics: + {{- with .Values.controller.autoscaling.metrics }} + {{- toYaml . | nindent 4 }} + {{- else }} + {{- with .Values.controller.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ . }} + {{- end }} + {{- with .Values.controller.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ . }} + {{- end }} + {{- end }} + {{- with .Values.controller.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/argo-rollouts/values.yaml b/charts/argo-rollouts/values.yaml index f9ae582c..12b5eb2e 100644 --- a/charts/argo-rollouts/values.yaml +++ b/charts/argo-rollouts/values.yaml @@ -61,6 +61,12 @@ controller: tolerations: [] # -- Assign custom [affinity] rules to the deployment affinity: {} + autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 2 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 logging: # -- Set the logging level (one of: `debug`, `info`, `warn`, `error`) level: info