From 4e9663c74742dd711c3371302f05251bc795e136 Mon Sep 17 00:00:00 2001 From: Petr Drastil Date: Thu, 25 Aug 2022 13:35:17 +0200 Subject: [PATCH] feat(argo-cd): Set ARGOCD_CONTROLLER_REPLICAS automatically (#1413) Signed-off-by: Petr Drastil --- charts/argo-cd/Chart.yaml | 5 +- charts/argo-cd/README.md | 2 +- charts/argo-cd/templates/_helpers.tpl | 10 +-- .../statefulset.yaml | 64 ++++++++++--------- charts/argo-cd/values.yaml | 7 +- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/charts/argo-cd/Chart.yaml b/charts/argo-cd/Chart.yaml index 97846d1f..e3f0acf7 100644 --- a/charts/argo-cd/Chart.yaml +++ b/charts/argo-cd/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: v2.4.11 description: A Helm chart for Argo CD, a declarative, GitOps continuous delivery tool for Kubernetes. name: argo-cd -version: 5.3.0 +version: 5.3.1 home: https://github.com/argoproj/argo-helm icon: https://argo-cd.readthedocs.io/en/stable/assets/logo.png keywords: @@ -21,5 +21,4 @@ dependencies: condition: redis-ha.enabled annotations: artifacthub.io/changes: | - - "[Added]: Global configuration for logging" - - "[Added]: ApplicationSet configuration for logging" + - "[Changed]: Env variable ARGOCD_CONTROLLER_REPLICAS is now automatically set by replica count" diff --git a/charts/argo-cd/README.md b/charts/argo-cd/README.md index afdef972..d12ce196 100644 --- a/charts/argo-cd/README.md +++ b/charts/argo-cd/README.md @@ -437,7 +437,7 @@ NAME: my-release | controller.readinessProbe.periodSeconds | int | `10` | How often (in seconds) to perform the [probe] | | controller.readinessProbe.successThreshold | int | `1` | Minimum consecutive successes for the [probe] to be considered successful after having failed | | controller.readinessProbe.timeoutSeconds | int | `1` | Number of seconds after which the [probe] times out | -| controller.replicas | int | `1` | The number of application controller pods to run. If changing the number of replicas you must pass the number as `ARGOCD_CONTROLLER_REPLICAS` as an environment variable | +| controller.replicas | int | `1` | The number of application controller pods to run. Additional replicas will cause sharding of managed clusters across number of replicas. | | controller.resources | object | `{}` | Resource limits and requests for the application controller pods | | controller.service.annotations | object | `{}` | Application controller service annotations | | controller.service.labels | object | `{}` | Application controller service labels | diff --git a/charts/argo-cd/templates/_helpers.tpl b/charts/argo-cd/templates/_helpers.tpl index bfd0d41c..d34dc0bd 100644 --- a/charts/argo-cd/templates/_helpers.tpl +++ b/charts/argo-cd/templates/_helpers.tpl @@ -265,17 +265,13 @@ Return the default Argo CD app version {{- end -}} {{- define "argo-cd.redisPasswordEnv" -}} - {{- if or .Values.externalRedis.password .Values.externalRedis.existingSecret }} +{{- if or .Values.externalRedis.password .Values.externalRedis.existingSecret -}} - name: REDIS_PASSWORD valueFrom: secretKeyRef: - {{- if .Values.externalRedis.existingSecret }} - name: {{ .Values.externalRedis.existingSecret }} - {{- else }} - name: {{ template "argo-cd.redis.fullname" . }} - {{- end }} + name: {{ default (include "argo-cd.redis.fullname" .) .Values.externalRedis.existingSecret }} key: redis-password - {{- end }} +{{- end -}} {{- end -}} {{/* diff --git a/charts/argo-cd/templates/argocd-application-controller/statefulset.yaml b/charts/argo-cd/templates/argocd-application-controller/statefulset.yaml index eccc9b5b..e5442d0f 100755 --- a/charts/argo-cd/templates/argocd-application-controller/statefulset.yaml +++ b/charts/argo-cd/templates/argocd-application-controller/statefulset.yaml @@ -68,23 +68,25 @@ spec: - {{ .Values.externalRedis.host }}:{{ .Values.externalRedis.port }} {{- end }} {{- with .Values.controller.extraArgs }} - {{- . | toYaml | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} image: {{ default .Values.global.image.repository .Values.controller.image.repository }}:{{ default (include "argo-cd.defaultTag" .) .Values.controller.image.tag }} imagePullPolicy: {{ default .Values.global.image.imagePullPolicy .Values.controller.image.imagePullPolicy }} name: {{ .Values.controller.name }} - {{- if .Values.controller.containerSecurityContext }} - securityContext: {{- toYaml .Values.controller.containerSecurityContext | nindent 10 }} + {{- with .Values.controller.containerSecurityContext }} + securityContext: + {{- toYaml . | nindent 10 }} {{- end }} - {{- if or .Values.controller.env .Values.externalRedis.password .Values.externalRedis.existingSecret }} env: - {{- include "argo-cd.redisPasswordEnv" . | nindent 8 }} {{- with .Values.controller.env }} - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 10 }} {{- end }} - {{- end }} + - name: ARGOCD_CONTROLLER_REPLICAS + value: {{ .Values.controller.replicas | quote }} + {{- include "argo-cd.redisPasswordEnv" . | nindent 10 }} {{- with .Values.controller.envFrom }} - envFrom: {{- toYaml . | nindent 8 }} + envFrom: + {{- toYaml . | nindent 10 }} {{- end }} ports: - name: controller @@ -121,29 +123,29 @@ spec: {{- with .Values.controller.extraContainers }} {{- toYaml . | nindent 6 }} {{- end }} - {{- if .Values.controller.nodeSelector }} + {{- with .Values.controller.nodeSelector }} nodeSelector: -{{- toYaml .Values.controller.nodeSelector | nindent 8 }} - {{- end }} - {{- if .Values.controller.tolerations }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.controller.tolerations }} tolerations: -{{- toYaml .Values.controller.tolerations | nindent 8 }} - {{- end }} - {{- if .Values.controller.affinity }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.controller.affinity }} affinity: -{{- toYaml .Values.controller.affinity | nindent 8 }} - {{- end }} - {{- with .Values.controller.topologySpreadConstraints }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.controller.topologySpreadConstraints }} topologySpreadConstraints: - {{- range $constraint := . }} - - {{ toYaml $constraint | nindent 8 | trim }} - {{- if not $constraint.labelSelector }} - labelSelector: - matchLabels: - {{- include "argo-cd.selectorLabels" (dict "context" $ "name" $.Values.controller.name) | nindent 12 }} + {{- range $constraint := . }} + - {{ toYaml $constraint | nindent 8 | trim }} + {{- if not $constraint.labelSelector }} + labelSelector: + matchLabels: + {{- include "argo-cd.selectorLabels" (dict "context" $ "name" $.Values.controller.name) | nindent 12 }} + {{- end }} {{- end }} {{- end }} - {{- end }} serviceAccountName: {{ template "argo-cd.controllerServiceAccountName" . }} {{- with .Values.global.hostAliases }} hostAliases: @@ -164,12 +166,12 @@ spec: optional: true secretName: argocd-repo-server-tls {{- with .Values.controller.volumes }} - {{- toYaml . | nindent 6 }} + {{- toYaml . | nindent 6 }} {{- end }} - {{- if .Values.controller.initContainers }} + {{- with .Values.controller.initContainers }} initContainers: - {{- toYaml .Values.controller.initContainers | nindent 6 }} + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.controller.priorityClassName }} + priorityClassName: {{ . }} {{- end }} -{{- if .Values.controller.priorityClassName }} - priorityClassName: {{ .Values.controller.priorityClassName }} -{{- end }} diff --git a/charts/argo-cd/values.yaml b/charts/argo-cd/values.yaml index 3d64ec3c..e69bbb19 100755 --- a/charts/argo-cd/values.yaml +++ b/charts/argo-cd/values.yaml @@ -119,7 +119,7 @@ controller: imagePullPolicy: "" # -- The number of application controller pods to run. - # If changing the number of replicas you must pass the number as `ARGOCD_CONTROLLER_REPLICAS` as an environment variable + # Additional replicas will cause sharding of managed clusters across number of replicas. replicas: 1 ## Application controller commandline flags @@ -146,10 +146,7 @@ controller: extraArgs: [] # -- Environment variables to pass to application controller - env: - [] - # - name: "ARGOCD_CONTROLLER_REPLICAS" - # value: "" + env: [] # -- envFrom to pass to application controller # @default -- `[]` (See [values.yaml])