Skip to content

Commit 69d767e

Browse files
refactor cf-argocd-extras
1 parent da2c7ad commit 69d767e

File tree

20 files changed

+797
-1068
lines changed

20 files changed

+797
-1068
lines changed

charts/gitops-runtime/Chart.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
- name: argo-events
2222
repository: https://codefresh-io.github.io/argo-helm
2323
version: 2.4.9-cap-CR-30841
24+
condition: argo-events.enabled
2425
- name: argo-workflows
2526
repository: https://codefresh-io.github.io/argo-helm
2627
version: 0.45.16-v3.6.7-cap-CR-30835
@@ -37,6 +38,3 @@ dependencies:
3738
version: 0.1.22
3839
alias: tunnel-client
3940
condition: tunnel-client.enabled
40-
- name: cf-common
41-
repository: oci://quay.io/codefresh/charts
42-
version: 0.27.0

charts/gitops-runtime/templates/_components/cap-app-proxy/_deployment.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{- define "cap-app-proxy.resources.deployment" }}
2-
{{- $cfCommonTplSemver := printf "cf-common-%s" (index .Subcharts "cf-common").Chart.Version }}
32
apiVersion: apps/v1
43
kind: Deployment
54
metadata:
@@ -89,7 +88,7 @@ spec:
8988
readOnly: true
9089
{{- if gt (int .Values.replicaCount) 1 }}
9190
- name: leader-elector
92-
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" (index .Values "leader-elector" "image") "context" .) }}
91+
image: {{ include "codefresh-gitops-runtime.image.name" (dict "image" (index .Values "leader-elector" "image") "context" .) }}
9392
imagePullPolicy: {{ index .Values "leader-elector" "image" "pullPolicy" | default "IfNotPresent" }}
9493
command:
9594
- leader-elector
@@ -154,7 +153,7 @@ spec:
154153
{{- toYaml . | nindent 6 }}
155154
{{- end }}
156155
{{- with .Values.topologySpreadConstraints }}
157-
topologySpreadConstraints: {{- include (printf "%s.tplrender" $cfCommonTplSemver ) (dict "Values" . "context" .) | nindent 8 }}
156+
topologySpreadConstraints: {{- include "codefresh-gitops-runtime.tplrender" (dict "Values" . "context" .) | nindent 8 }}
158157
{{- end }}
159158
volumes:
160159
{{- with .Values.extraVolumes }}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{- define "gitops-operator.resources.deployment" }}
2-
{{- $cfCommonTplSemver := printf "cf-common-%s" (index .Subcharts "cf-common").Chart.Version }}
32
{{/* Merge environment variables from calculated, defaults and overwrites */}}
43
{{- $defaults := (include "gitops-operator.resources.environment-variables.defaults" . | fromYaml) }}
54
{{- $calculated := (include "gitops-operator.resources.environment-variables.calculated" . | fromYaml) }}
@@ -43,8 +42,8 @@ spec:
4342
{{- if not (get $imageContext "tag") }}
4443
{{- $_ := set $imageContext "tag" .Chart.AppVersion }}
4544
{{- end }}
46-
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $imageContext "context" .) }}
47-
env: {{- include (printf "%s.env-vars" $cfCommonTplSemver ) (dict "Values" $mergedValues "context" .) | nindent 8 }}
45+
image: {{ include "codefresh-gitops-runtime.image.name" (dict "image" $imageContext "context" .) }}
46+
env: {{- include "codefresh-gitops-runtime.env-vars" (dict "Values" $mergedValues "context" .) | nindent 8 }}
4847
imagePullPolicy: {{ .Values.image.pullPolicy }}
4948
{{- if .Values.command }}
5049
command:
@@ -100,7 +99,7 @@ spec:
10099
affinity: {{ toYaml . | nindent 8 }}
101100
{{- end }}
102101
{{- with .Values.topologySpreadConstraints }}
103-
topologySpreadConstraints: {{- include (printf "%s.tplrender" $cfCommonTplSemver ) (dict "Values" . "context" .) | nindent 8 }}
102+
topologySpreadConstraints: {{- include "codefresh-gitops-runtime.tplrender" (dict "Values" . "context" .) | nindent 8 }}
104103
{{- end }}
105104
volumes:
106105
- name: tls-certs

charts/gitops-runtime/templates/_components/internal-router/_deployment.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{- define "internal-router.resources.deployment" }}
2-
{{- $cfCommonTplSemver := printf "cf-common-%s" (index .Subcharts "cf-common").Chart.Version }}
32
apiVersion: apps/v1
43
kind: Deployment
54
metadata:
@@ -84,6 +83,6 @@ spec:
8483
{{- toYaml . | nindent 8 }}
8584
{{- end }}
8685
{{- with .Values.topologySpreadConstraints }}
87-
topologySpreadConstraints: {{- include (printf "%s.tplrender" $cfCommonTplSemver ) (dict "Values" . "context" .) | nindent 8 }}
86+
topologySpreadConstraints: {{- include "codefresh-gitops-runtime.tplrender" (dict "Values" . "context" .) | nindent 8 }}
8887
{{- end }}
8988
{{- end }}

charts/gitops-runtime/templates/_helpers.tpl

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,19 @@ Get ingress url for both tunnel based and ingress based runtimes
430430
Output comma separated list of installed runtime components
431431
*/}}
432432
{{- define "codefresh-gitops-runtime.component-list"}}
433-
{{- $argoEvents := dict "name" "argo-events" "version" (get .Subcharts "argo-events").Chart.AppVersion }}
434433
{{- $sealedSecrets := dict "name" "sealed-secrets" "version" (get .Subcharts "sealed-secrets").Chart.AppVersion }}
435434
{{- $internalRouter := dict "name" "internal-router" "version" .Chart.AppVersion }}
436435
{{- $appProxy := dict "name" "app-proxy" "version" (index (get .Values "app-proxy") "image" "tag") }}
437436
{{- $argoApiGateway := dict "name" "argo-api-gateway" "version" (get .Values "argo-api-gateway").image.tag }}
438-
{{- $comptList := list $argoEvents $appProxy $sealedSecrets $internalRouter $argoApiGateway }}
439-
{{- if and (index .Values "argo-cd" "enabled") }}
440-
{{- $argoCD := dict "name" "argocd" "version" (get .Subcharts "argo-cd").Chart.AppVersion }}
441-
{{- $comptList = append $comptList $argoCD }}
442-
{{- end }}
437+
{{- $comptList := list $appProxy $sealedSecrets $internalRouter $argoApiGateway }}
438+
{{- if and (index .Values "argo-cd" "enabled") }}
439+
{{- $argoCD := dict "name" "argocd" "version" (get .Subcharts "argo-cd").Chart.AppVersion }}
440+
{{- $comptList = append $comptList $argoCD }}
441+
{{- end }}
442+
{{- if index (get .Values "argo-events") "enabled" }}
443+
{{- $argoEvents := dict "name" "argo-events" "version" (get .Subcharts "argo-events").Chart.AppVersion }}
444+
{{- $comptList = append $comptList $argoEvents }}
445+
{{- end }}
443446
{{- if index (get .Values "argo-rollouts") "enabled" }}
444447
{{- $rolloutReporter := dict "name" "rollout-reporter" "version" .Chart.AppVersion }}
445448
{{- $argoRollouts := dict "name" "argo-rollouts" "version" (get .Subcharts "argo-rollouts").Chart.AppVersion }}
@@ -461,7 +464,7 @@ Output comma separated list of installed runtime components
461464
{{- $comptList = append $comptList $gitopsOperator }}
462465
{{- end }}
463466
{{- if not (index .Values "argo-cd" "enabled") }}
464-
{{- $eventReporter := dict "name" "event-reporter" "version" (index (get .Values "event-reporters") "runtime-reporter" "image" "tag") }}
467+
{{- $eventReporter := dict "name" "event-reporter" "version" (index .Values "global" "event-reporters" "image" "tag") }}
465468
{{- $comptList = append $comptList $eventReporter }}
466469
{{- end }}
467470
{{- $comptList | toYaml }}
@@ -536,3 +539,76 @@ NO_PROXY: {{ .Values.global.noProxy | quote }}
536539

537540
{{- printf "%s" $eventBusName }}
538541
{{- end }}
542+
543+
544+
{{- define "codefresh-gitops-runtime.image.name" -}}
545+
{{/* Restoring root $ context */}}
546+
{{- $ := .context -}}
547+
548+
{{- $registryName := .image.registry -}}
549+
{{- $repositoryName := .image.repository -}}
550+
{{- $imageTag := .image.tag | toString -}}
551+
{{- $imageDigest := .image.digest }}
552+
553+
{{- if $.Values.global -}}
554+
{{- if $.Values.global.imageRegistry -}}
555+
{{ $registryName = $.Values.global.imageRegistry }}
556+
{{- end -}}
557+
{{- end -}}
558+
559+
{{- if $registryName -}}
560+
{{- if $imageDigest }}
561+
{{- printf "%s/%s:%s@%s" $registryName $repositoryName $imageTag $imageDigest -}}
562+
{{- else }}
563+
{{- printf "%s/%s:%s" $registryName $repositoryName $imageTag -}}
564+
{{- end }}
565+
{{- else }}
566+
{{- if $imageDigest }}
567+
{{- printf "%s:%s@%s" $repositoryName $imageTag $imageDigest -}}
568+
{{- else }}
569+
{{- printf "%s:%s" $repositoryName $imageTag -}}
570+
{{- end }}
571+
{{- end }}
572+
{{- end }}
573+
574+
{{- define "codefresh-gitops-runtime.env-vars"}}
575+
{{- $ := .context }}
576+
{{- if .Values }}
577+
{{- if not (kindIs "map" .Values) }}
578+
{{ fail "ERROR: env block must be a map"}}
579+
{{- end }}
580+
{{- end }}
581+
{{- $env := .Values }}
582+
{{- $templatedEnv := include "codefresh-gitops-runtime.tplrender" (dict "Values" $env "context" $) | fromYaml }}
583+
{{- range $name, $val := $templatedEnv }}
584+
{{- if or (kindIs "string" $val) (kindIs "bool" $val) (kindIs "int" $val) (kindIs "float64" $val) }}
585+
- name: {{ $name }}
586+
value: {{ $val | quote }}
587+
{{- else if kindIs "map" $val}}
588+
{{- if hasKey $val "valueFrom" }}
589+
{{- if or (hasKey $val.valueFrom "secretKeyRef") (hasKey $val.valueFrom "configMapKeyRef") (hasKey $val.valueFrom "fieldRef") }}
590+
- name: {{ $name }}
591+
{{- $val | toYaml | nindent 2 }}
592+
{{- else}}
593+
{{ fail "ERROR: Only secretKeyRef/configMapKeyRef/fieldRef are supported for valueFrom block for environment variables!" }}
594+
{{- end}}
595+
{{- else }}
596+
{{ fail "ERROR: Cannot generate environment variables only strings and valueFrom are supported!"}}
597+
{{- end }}
598+
{{- else }}
599+
{{ fail "ERROR: Only maps and string/int/bool are supported for environment variables!"}}
600+
{{- end }}
601+
{{- end }}
602+
{{- end }}
603+
604+
{{- define "codefresh-gitops-runtime.tplrender" -}}
605+
{{- $tpl := .Values -}}
606+
{{- if not (typeIs "string" $tpl) -}}
607+
{{- $tpl = toYaml $tpl -}}
608+
{{- end -}}
609+
{{- if contains "{{" $tpl -}}
610+
{{- tpl $tpl .context }}
611+
{{- else -}}
612+
{{- $tpl -}}
613+
{{- end -}}
614+
{{- end -}}

charts/gitops-runtime/templates/argo-api-gateway/_env.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ NO_PROXY: {{ .Values.global.noProxy | squote }}
55

66
{{- if and (eq (index .Values "global" "external-argo-cd" "auth" "type") "token") }}
77
{{- if not (index .Values "global" "external-argo-cd" "auth" "token") }}
8-
ARGO_CD_TOKEN_SECRET_NAME: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore Values.global.external-argo-cd.auth.tokenSecretKeyRef.name is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "name") }}
9-
ARGO_CD_TOKEN_SECRET_KEY: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore Values.global.external-argo-cd.auth.tokenSecretKeyRef.key is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "key" ) }}
8+
ARGO_CD_TOKEN_SECRET_NAME: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore .global.external-argo-cd.auth.tokenSecretKeyRef.name is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "name") }}
9+
ARGO_CD_TOKEN_SECRET_KEY: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore .global.external-argo-cd.auth.tokenSecretKeyRef.key is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "key" ) }}
1010
{{- else }}
1111
ARGO_CD_TOKEN_SECRET_NAME: "gitops-runtime-argo-cd-token"
1212
ARGO_CD_TOKEN_SECRET_KEY: "token"
1313
{{- end }}
1414
{{- end }}
1515

16-
{{- if and (index .Values "global" "external-argo-cd" "server" "rootpath") }}
17-
ARGOCD_SERVER_ROOTPATH: {{ index .Values "global" "external-argo-cd" "server" "rootpath" }}
16+
{{- with (index .Values "global" "external-argo-cd" "server" "rootpath") }}
17+
ARGOCD_SERVER_ROOTPATH: {{ . }}
1818
{{- end }}
1919

2020
{{- if or .Values.global.codefresh.tls.caCerts.secret.create (and .Values.global.codefresh.tls.caCerts.secretKeyRef.key .Values.global.codefresh.tls.caCerts.secretKeyRef.name) }}

charts/gitops-runtime/templates/argo-api-gateway/_helpers.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Selector labels
3333
*/}}
3434
{{- define "argo-api-gateway.selectorLabels" -}}
3535
app.kubernetes.io/name: argo-api-gateway
36+
app.kubernetes.io/instance: {{ .Release.Name }}
3637
{{- end }}
3738

3839
{{/*

charts/gitops-runtime/templates/argo-api-gateway/configmap.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{{- define "argo-api-gateway.resources.configmap.defaults"}}
1+
{{- define "argo-api-gateway.resources.configmap.defaults" }}
22
argocd.server: {{ include "codefresh-gitops-runtime.argocd.server.no-protocol-url" . }}
33
repo.server: {{ include "codefresh-gitops-runtime.argocd.reposerver.url" . }}
4+
redis.server: {{ include "codefresh-gitops-runtime.argocd.redis.url" . }}
45
{{- end }}
56

67
{{- $defaultConfig := (include "argo-api-gateway.resources.configmap.defaults" . | fromYaml ) }}
@@ -14,3 +15,8 @@ metadata:
1415
{{- include "argo-api-gateway.labels" . | nindent 4 }}
1516
data:
1617
{{- $mergedConfig | toYaml | nindent 2 }}
18+
{{- if index .Values "argo-cd" "enabled" }}
19+
foo: bar
20+
{{- else }}
21+
baz: qux
22+
{{- end }}

charts/gitops-runtime/templates/argo-api-gateway/deployment.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
{{- $cfCommonTplSemver := printf "cf-common-%s" (index .Subcharts "cf-common").Chart.Version }}
21
{{- $context := deepCopy . }}
32
{{- $_ := set $context "Values" (deepCopy (get .Values "argo-api-gateway")) }}
43
{{- $_ := set $context.Values "global" (deepCopy (get .Values "global")) }}
54
{{/* Merge environment variables from calculated, defaults and overwrites */}}
6-
{{- $defaults := (include "argo-api-gateway.resources.environment-variables.defaults" . | fromYaml) }}
7-
{{- $calculated := (include "argo-api-gateway.resources.environment-variables.calculated" . | fromYaml) }}
5+
{{- $defaults := (include "argo-api-gateway.resources.environment-variables.defaults" $context | fromYaml) }}
6+
{{- $calculated := (include "argo-api-gateway.resources.environment-variables.calculated" $context | fromYaml) }}
87
{{- $overrides := $context.Values.env }}
98
{{- $mergedValues := mergeOverwrite $defaults $calculated $overrides }}
109
apiVersion: apps/v1
@@ -42,8 +41,8 @@ spec:
4241
securityContext:
4342
{{- toYaml $context.Values.securityContext | nindent 12 }}
4443
{{- $imageContext := deepCopy $context.Values.image }}
45-
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $imageContext "context" .) }}
46-
env: {{- include (printf "%s.env-vars" $cfCommonTplSemver ) (dict "Values" $mergedValues "context" .) | nindent 8 }}
44+
image: {{ include "codefresh-gitops-runtime.image.name" (dict "image" $imageContext "context" .) }}
45+
env: {{- include "codefresh-gitops-runtime.env-vars" (dict "Values" $mergedValues "context" .) | nindent 8 }}
4746
imagePullPolicy: {{ $context.Values.image.pullPolicy }}
4847
{{- if $context.Values.command }}
4948
command:
@@ -77,9 +76,10 @@ spec:
7776
resources:
7877
{{- toYaml $context.Values.resources | nindent 10 }}
7978
volumeMounts:
80-
{{- if $context.Values.global.codefresh.tls.caCerts.secretKeyRef }}
81-
- name: codefresh-tls
82-
mountPath: /app/config/codefresh-tls
79+
{{- if or $context.Values.global.codefresh.tls.caCerts.secretKeyRef $context.Values.global.codefresh.tls.caCerts.secret.create }}
80+
- name: codefresh-tls-certs
81+
mountPath: /app/config/codefresh-tls-certs
82+
readOnly: true
8383
{{- end }}
8484
{{- with $context.Values.extraVolumeMounts }}
8585
{{- toYaml . | nindent 8 }}
@@ -94,13 +94,13 @@ spec:
9494
affinity: {{ toYaml . | nindent 8 }}
9595
{{- end }}
9696
{{- with $context.Values.topologySpreadConstraints }}
97-
topologySpreadConstraints: {{- include (printf "%s.tplrender" $cfCommonTplSemver ) (dict "Values" . "context" .) | nindent 8 }}
97+
topologySpreadConstraints: {{- include "codefresh-gitops-runtime.tplrender" (dict "Values" . "context" .) | nindent 8 }}
9898
{{- end }}
9999
volumes:
100-
{{- if $context.Values.global.codefresh.tls.caCerts.secretKeyRef }}
101-
- name: codefresh-tls
100+
{{- if or $context.Values.global.codefresh.tls.caCerts.secretKeyRef $context.Values.global.codefresh.tls.caCerts.secret.create }}
101+
- name: codefresh-tls-certs
102102
secret:
103-
secretName: {{ $context.Values.global.codefresh.tls.caCerts.secretKeyRef.name }}
103+
secretName: {{ $context.Values.global.codefresh.tls.caCerts.secretKeyRef.name | default "codefresh-tls-certs" }}
104104
{{- end }}
105105
{{- with $context.Values.extraVolumes }}
106106
{{- toYaml . | nindent 6 }}

charts/gitops-runtime/templates/event-reporters/resources-reporter/_env.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ NO_PROXY: {{ .Values.global.noProxy | squote }}
55

66
{{- if and (eq (index .Values "global" "external-argo-cd" "auth" "type") "token") }}
77
{{- if not (index .Values "global" "external-argo-cd" "auth" "token") }}
8-
ARGO_CD_TOKEN_SECRET_NAME: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore Values.global.external-argo-cd.auth.tokenSecretKeyRef.name is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "name") }}
9-
ARGO_CD_TOKEN_SECRET_KEY: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore Values.global.external-argo-cd.auth.tokenSecretKeyRef.key is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "key" ) }}
8+
ARGO_CD_TOKEN_SECRET_NAME: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore .global.external-argo-cd.auth.tokenSecretKeyRef.name is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "name") }}
9+
ARGO_CD_TOKEN_SECRET_KEY: {{ required ".Values.global.external-argo-cd.auth.type is set to 'token' therefore .global.external-argo-cd.auth.tokenSecretKeyRef.key is required" (index .Values "global" "external-argo-cd" "auth" "tokenSecretKeyRef" "key" ) }}
1010
{{- else }}
1111
ARGO_CD_TOKEN_SECRET_NAME: "gitops-runtime-argo-cd-token"
1212
ARGO_CD_TOKEN_SECRET_KEY: "token"
1313
{{- end }}
1414
{{- end }}
1515

16-
{{- if and (index .Values "global" "external-argo-cd" "server" "rootpath") }}
17-
ARGOCD_SERVER_ROOTPATH: {{ index .Values "global" "external-argo-cd" "server" "rootpath" }}
16+
{{- with (index .Values "global" "external-argo-cd" "server" "rootpath") }}
17+
ARGOCD_SERVER_ROOTPATH: {{ . }}
1818
{{- end }}
1919

2020
{{- if or .Values.global.codefresh.tls.caCerts.secret.create (and .Values.global.codefresh.tls.caCerts.secretKeyRef.key .Values.global.codefresh.tls.caCerts.secretKeyRef.name) }}

0 commit comments

Comments
 (0)