Skip to content

Commit

Permalink
Equivalent templates but removes break and continue, which are only o…
Browse files Browse the repository at this point in the history
…n newer versions of Helm (#1170)

Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall authored Jan 25, 2025
1 parent 538fe77 commit e47d197
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ create
{{- define "secrets.getSecretFromRef" -}}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." (printf "%sFrom" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordFrom"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand All @@ -40,13 +39,12 @@ create
{{- $value := .object -}}
{{- $defaultKey := (( regexSplit "\\." .key -1) | last) -}} {{/* "path.to.auth.password" --> "password" */}}
{{- range $pathPart := (regexSplit "\\." (printf "%sKey" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordKey"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = $defaultKey -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = $defaultKey -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand All @@ -58,13 +56,12 @@ create
{{- $found := true}}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." (printf "%sKey" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordKey"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $found = false -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $found = false -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $found -}}
Expand All @@ -75,13 +72,12 @@ create
{{- define "secrets.getSecretValue" }}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." .key -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "password"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand Down Expand Up @@ -129,9 +125,9 @@ remote.kubernetes.secret.{{ include "helper.alloy_name" .object.name }}.data[{{
{{- $keyDefined := include "secrets.isSecretKeyDefined" (dict "object" $ "key" $secret) -}}
{{- $value := include "secrets.getSecretValue" (dict "object" $ "key" $secret) -}}
{{- if (eq $secretType "external") }}
{{- if eq $keyDefined "true" }}{{- $usesK8sSecret = true }}{{ break }}{{- end }}
{{- if eq $keyDefined "true" }}{{- $usesK8sSecret = true }}{{- end }}
{{- else }}
{{- if and $value (not $ref) }}{{- $usesK8sSecret = true }}{{ break }}{{- end }}
{{- if and $value (not $ref) }}{{- $usesK8sSecret = true }}{{- end }}
{{- end }}
{{- end }}
{{- $usesK8sSecret -}}
Expand Down
56 changes: 26 additions & 30 deletions charts/k8s-monitoring/templates/secrets/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ create
{{- define "secrets.getSecretFromRef" -}}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." (printf "%sFrom" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordFrom"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand All @@ -40,13 +39,12 @@ create
{{- $value := .object -}}
{{- $defaultKey := (( regexSplit "\\." .key -1) | last) -}} {{/* "path.to.auth.password" --> "password" */}}
{{- range $pathPart := (regexSplit "\\." (printf "%sKey" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordKey"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = $defaultKey -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = $defaultKey -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand All @@ -58,13 +56,12 @@ create
{{- $found := true}}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." (printf "%sKey" .key) -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "passwordKey"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $found = false -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $found = false -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $found -}}
Expand All @@ -75,13 +72,12 @@ create
{{- define "secrets.getSecretValue" }}
{{- $value := .object -}}
{{- range $pathPart := (regexSplit "\\." .key -1) -}} {{/* "path.to.auth.password" --> ["path", "to", "auth" "password"] */}}
{{- if not $pathPart -}}
{{- continue -}}
{{- else if hasKey $value $pathPart -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- break -}}
{{- if $pathPart -}}
{{- if and (not (kindIs "string" $value)) (hasKey $value $pathPart) -}}
{{- $value = (index $value $pathPart) -}}
{{- else -}}
{{- $value = "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $value -}}
Expand Down Expand Up @@ -129,9 +125,9 @@ remote.kubernetes.secret.{{ include "helper.alloy_name" .object.name }}.data[{{
{{- $keyDefined := include "secrets.isSecretKeyDefined" (dict "object" $ "key" $secret) -}}
{{- $value := include "secrets.getSecretValue" (dict "object" $ "key" $secret) -}}
{{- if (eq $secretType "external") }}
{{- if eq $keyDefined "true" }}{{- $usesK8sSecret = true }}{{ break }}{{- end }}
{{- if eq $keyDefined "true" }}{{- $usesK8sSecret = true }}{{- end }}
{{- else }}
{{- if and $value (not $ref) }}{{- $usesK8sSecret = true }}{{ break }}{{- end }}
{{- if and $value (not $ref) }}{{- $usesK8sSecret = true }}{{- end }}
{{- end }}
{{- end }}
{{- $usesK8sSecret -}}
Expand Down

0 comments on commit e47d197

Please sign in to comment.