Skip to content

Commit 2ca7c2d

Browse files
committed
added "codefresh-gitops-runtime.argocd-token-auth"
simplified event-terpoter/sources-server/gitops-operator argo-cd auth secret name/key injection
1 parent 0991145 commit 2ca7c2d

File tree

8 files changed

+38
-62
lines changed

8 files changed

+38
-62
lines changed

charts/gitops-runtime/templates/_components/cf-argocd-extras/_default-values.tpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- define "cf-argocd-extras.default-values" }}
2+
{{- $argoCdAuth := (include "codefresh-gitops-runtime.argocd-token-auth" . | fromYaml) }}
23
global: {}
34

45
externalRedis:
@@ -84,8 +85,7 @@ eventReporter:
8485
name: argocd-cmd-params-cm
8586
key: server.rootpath
8687
optional: true
87-
ARGO_CD_TOKEN_SECRET_NAME: argocd-token
88-
ARGO_CD_TOKEN_SECRET_KEY: token
88+
{{ $argoCdAuth | toYaml | indent 6 }}
8989
BINARY_NAME: event-reporter
9090
CODEFRESH_SSL_CERT_PATH: ""
9191
CODEFRESH_TLS_INSECURE:
@@ -392,8 +392,7 @@ sourcesServer:
392392
configMapKeyRef:
393393
name: sources-server-cmd-params-cm
394394
key: argocd.server
395-
ARGO_CD_TOKEN_SECRET_NAME: argocd-token
396-
ARGO_CD_TOKEN_SECRET_KEY: token
395+
{{ $argoCdAuth | toYaml | indent 6}}
397396
ARGOCD_SERVER_ROOTPATH:
398397
valueFrom:
399398
configMapKeyRef:

charts/gitops-runtime/templates/_components/cf-argocd-extras/event-reporter/_statefulset.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
{{- $_ := set $context.Values.container.env.REDIS_PASSWORD.valueFrom.secretKeyRef "key" (default "redis-password" $vals.externalRedis.existingSecretKeyRef.key) }}
1616
{{- end }}
1717

18-
{{- $argoCdAuth := (index .Values "global" "integrations" "argo-cd" "server" "auth") }}
19-
{{- if (eq $argoCdAuth.type "token") }}
20-
{{- if $argoCdAuth.token }}
21-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_NAME" "gitops-runtime-argo-cd-token" }}
22-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_KEY" "token" }}
23-
{{- else if $argoCdAuth.tokenSecretKeyRef }}
24-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_NAME" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.name is required" $argoCdAuth.tokenSecretKeyRef.name) }}
25-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_KEY" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.key is required" $argoCdAuth.tokenSecretKeyRef.key) }}
26-
{{- else }}
27-
{{ fail ".Values.global.integrations.argo-cd.auth.type is 'token' and .Values.global.integrations.argo-cd.auth.token or .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef are not set" }}
28-
{{- end }}
29-
{{- end }}
30-
3118
{{- if and (index $context.Values "global" "external-argo-cd" "server" "rootpath") }}
3219
{{- $_ := set $context.Values.container.env "ARGOCD_SERVER_ROOTPATH" (index $context.Values "global" "external-argo-cd" "server" "rootpath") }}
3320
{{- end }}

charts/gitops-runtime/templates/_components/cf-argocd-extras/sources-server/_deployment.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
{{- $_ := set $context.Values.container.env.REDIS_PASSWORD.valueFrom.secretKeyRef "key" (default "redis-password" $vals.externalRedis.existingSecretKeyRef.key) }}
1616
{{- end }}
1717

18-
{{- $argoCdAuth := (index .Values "global" "integrations" "argo-cd" "server" "auth") }}
19-
{{- if (eq $argoCdAuth.type "token") }}
20-
{{- if $argoCdAuth.token }}
21-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_NAME" "gitops-runtime-argo-cd-token" }}
22-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_KEY" "token" }}
23-
{{- else if $argoCdAuth.tokenSecretKeyRef }}
24-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_NAME" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.name is required" $argoCdAuth.tokenSecretKeyRef.name) }}
25-
{{- $_ := set $context.Values.container.env "ARGO_CD_TOKEN_SECRET_KEY" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.key is required" $argoCdAuth.tokenSecretKeyRef.key) }}
26-
{{- else }}
27-
{{ fail ".Values.global.integrations.argo-cd.auth.type is 'token' and .Values.global.integrations.argo-cd.auth.token or .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef are not set" }}
28-
{{- end }}
29-
{{- end }}
30-
3118
{{- if and (index $context.Values "global" "external-argo-cd" "server" "rootpath") }}
3219
{{- $_ := set $context.Values.container.env "ARGOCD_SERVER_ROOTPATH" (index $context.Values "global" "external-argo-cd" "server" "rootpath") }}
3320
{{- end }}

charts/gitops-runtime/templates/_components/gitops-operator/_deployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
{{/* Merge environment variables from calculated, defaults and overwrites */}}
44
{{- $defaults := (include "gitops-operator.resources.environment-variables.defaults" . | fromYaml) }}
55
{{- $calculated := (include "gitops-operator.resources.environment-variables.calculated" . | fromYaml) }}
6+
{{- $argoCdAuth := (include "codefresh-gitops-runtime.argocd-token-auth" . | fromYaml) }}
67
{{- $overrides := .Values.env }}
7-
{{- $mergedValues := mergeOverwrite $defaults $calculated $overrides }}
8+
{{- $mergedValues := mergeOverwrite $defaults $calculated $argoCdAuth $overrides }}
89
apiVersion: apps/v1
910
kind: Deployment
1011
metadata:

charts/gitops-runtime/templates/_components/gitops-operator/_env.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ to keep the separation of components as pseudo library charts, they are defined
88
CF_CA_CERT: {{ printf "/app/config/codefresh-tls/%s" .Values.global.codefresh.tls.caCerts.secretKeyRef.key }}
99
{{- end }}
1010
CF_URL: {{ .Values.global.codefresh.url }}
11+
COMMIT_STATUS_POLLING_INTERVAL: {{ .Values.config.commitStatusPollingInterval }}
1112
GITOPS_OPERATOR_VERSION: {{ .Values.image.tag }}
13+
{{- if (gt (int .Values.replicaCount) 1 ) }}
14+
LEADER_ELECT: true
15+
{{- else }}
16+
LEADER_ELECT: false
17+
{{- end }}
18+
MAX_CONCURRENT_RELEASES: {{ .Values.config.maxConcurrentReleases }}
19+
PROMOTION_WRAPPER_TEMPLATE: {{ .Values.config.promotionWrapperTemplate | quote }}
1220
RUNTIME: {{ .Values.global.runtime.name }}
1321
TASK_POLLING_INTERVAL: {{ .Values.config.taskPollingInterval }}
14-
COMMIT_STATUS_POLLING_INTERVAL: {{ .Values.config.commitStatusPollingInterval }}
1522
WORKFLOW_MONITOR_POLLING_INTERVAL: {{ .Values.config.workflowMonitorPollingInterval }}
16-
MAX_CONCURRENT_RELEASES: {{ .Values.config.maxConcurrentReleases }}
17-
PROMOTION_WRAPPER_TEMPLATE: {{ .Values.config.promotionWrapperTemplate | quote }}
1823
{{- end }}
1924

2025
{{- define "gitops-operator.resources.environment-variables.defaults" -}}
2126
AP_URL: http://cap-app-proxy:3017
22-
ARGO_CD_URL: argo-cd-server:80
23-
ARGO_CD_TOKEN_SECRET_NAME: argocd-token
24-
ARGO_CD_TOKEN_SECRET_KEY: token
25-
ARGO_WF_URL: http://argo-server:2746
2627
CF_TOKEN:
2728
valueFrom:
2829
secretKeyRef:
2930
name: codefresh-token
3031
key: token
3132
HEALTH_PROBE_BIND_ADDRESS: :8081
32-
LEADER_ELECT: true
3333
METRICS_BIND_ADDRESS: :8080
3434
METRICS_SECURE: false
3535
NAMESPACE:

charts/gitops-runtime/templates/_helpers.tpl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,32 @@ ARGO_CD_TOKEN:
263263
{{- if and (hasKey $argoCdAuth.tokenSecretKeyRef "name") (hasKey $argoCdAuth.tokenSecretKeyRef "key") }}
264264
{{- $argoCdAuth.tokenSecretKeyRef | toYaml | nindent 6 }}
265265
{{- else }}
266-
{{- fail "Both 'name' and 'key' must be set in .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef" }}
266+
{{- fail "Both 'name' and 'key' must be set in .Values.global.integrations.argo-cd.server.auth.tokenSecretKeyRef" }}
267267
{{- end }}
268268
{{- end }}
269269
{{- else }}
270-
{{ fail (printf "Invalid value for .Values.global.integrations.argo-cd.auth.type: %s. Allowed values are: [password token]" $argoCdAuth.type) }}
270+
{{ fail (printf "Invalid value for .Values.global.integrations.argo-cd.server.auth.type: %s. Allowed values are: [password token]" $argoCdAuth.type) }}
271+
{{- end }}
272+
{{- end }}
273+
274+
{{/*
275+
Used by gitops-operator, event-reporter and sources-server to use the correct secret name/key for argo-cd token
276+
*/}}
277+
{{- define "codefresh-gitops-runtime.argocd-token-auth" }}
278+
{{- $argoCdAuth := (index .Values "global" "integrations" "argo-cd" "server" "auth") }}
279+
{{- if (eq $argoCdAuth.type "password") }}
280+
ARGO_CD_TOKEN_SECRET_NAME: argocd-token
281+
ARGO_CD_TOKEN_SECRET_KEY: token
282+
{{- else if (eq $argoCdAuth.type "token") }}
283+
{{- if $argoCdAuth.token }}
284+
ARGO_CD_TOKEN_SECRET_NAME: gitops-runtime-argo-cd-token
285+
ARGO_CD_TOKEN_SECRET_KEY: token
286+
{{- else if $argoCdAuth.tokenSecretKeyRef }}
287+
ARGO_CD_TOKEN_SECRET_NAME: {{ required ".Values.global.integrations.argo-cd.server.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.server.auth.tokenSecretKeyRef.name is required" $argoCdAuth.tokenSecretKeyRef.name }}
288+
ARGO_CD_TOKEN_SECRET_KEY: {{ required ".Values.global.integrations.argo-cd.server.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.server.auth.tokenSecretKeyRef.key is required" $argoCdAuth.tokenSecretKeyRef.key }}
289+
{{- end }}
290+
{{- else }}
291+
{{ fail (printf "Invalid value for .Values.global.integrations.argo-cd.server.auth.type: %s. Allowed values are: [password token]" $argoCdAuth.type) }}
271292
{{- end }}
272293
{{- end }}
273294

charts/gitops-runtime/templates/gitops-operator/deployment.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
{{- $_ := set $context "Values" $vals }}
77
{{- $_ := set $context.Values "global" (deepCopy (get .Values "global")) }}
88

9-
{{- $argoCdAuth := (index .Values "global" "integrations" "argo-cd" "server" "auth") }}
10-
{{- if (eq $argoCdAuth.type "token") }}
11-
{{- if $argoCdAuth.token }}
12-
{{- $_ := set $context.Values.env "ARGO_CD_TOKEN_SECRET_NAME" "gitops-runtime-argo-cd-token" }}
13-
{{- $_ := set $context.Values.env "ARGO_CD_TOKEN_SECRET_KEY" "token" }}
14-
{{- else if $argoCdAuth.tokenSecretKeyRef }}
15-
{{- $_ := set $context.Values.env "ARGO_CD_TOKEN_SECRET_NAME" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.name is required" $argoCdAuth.tokenSecretKeyRef.name) }}
16-
{{- $_ := set $context.Values.env "ARGO_CD_TOKEN_SECRET_KEY" (required ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.key is required" $argoCdAuth.tokenSecretKeyRef.key) }}
17-
{{- else }}
18-
{{ fail ".Values.global.integrations.argo-cd.auth.type is 'token' and .Values.global.integrations.argo-cd.auth.token or .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef are not set" }}
19-
{{- end }}
20-
{{- end }}
21-
229
{{/* Set argo-cd-server service and port */}}
2310
{{ if not (index $context.Values "env" "ARGO_CD_URL") }}
2411
{{- $_ := set $context.Values.env "ARGO_CD_URL" (include "codefresh-gitops-runtime.argocd.server.no-protocol-url" . ) }}
@@ -38,10 +25,4 @@
3825
{{- $_ := set $context.Values.global.codefresh.tls.caCerts.secretKeyRef "key" ($context.Values.global.codefresh.tls.caCerts.secret.create | ternary (default "ca-bundle.crt" $context.Values.global.codefresh.tls.caCerts.secret.key) $context.Values.global.codefresh.tls.caCerts.secretKeyRef.key) }}
3926
{{- end }}
4027

41-
{{- if and (gt (int $context.Values.replicaCount) 1 ) }}
42-
{{- $_ := set $context.Values.env "LEADER_ELECT" "true" }}
43-
{{- else }}
44-
{{- $_ := set $context.Values.env "LEADER_ELECT" "false" }}
45-
{{- end }}
46-
4728
{{- include "gitops-operator.resources.deployment" $context }}

charts/gitops-runtime/tests/external_argocd_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ tests:
715715
type: invalid
716716
asserts:
717717
- failedTemplate:
718-
errorMessage: "Invalid value for .Values.global.integrations.argo-cd.auth.type: invalid. Allowed values are: [password token]"
718+
errorMessage: "Invalid value for .Values.global.integrations.argo-cd.server.auth.type: invalid. Allowed values are: [password token]"
719719

720720
- it: event-reporter StatefulSet should have valid ARGOCD_SERVER_ROOTPATH env var
721721
template: cf-argocd-extras/event-reporter/statefulset.yaml
@@ -858,7 +858,7 @@ tests:
858858
key: null
859859
asserts:
860860
- failedTemplate:
861-
errorMessage: ".Values.global.integrations.argo-cd.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.auth.tokenSecretKeyRef.name is required"
861+
errorMessage: ".Values.global.integrations.argo-cd.server.auth.type is set to 'token' therefore .Values.global.integrations.argo-cd.server.auth.tokenSecretKeyRef.name is required"
862862

863863
- it: should require ArgoCd server address if it's not provided
864864
template: cf-argocd-extras/sources-server/deployment.yaml

0 commit comments

Comments
 (0)