Skip to content

Commit

Permalink
add secret helper function (#79)
Browse files Browse the repository at this point in the history
* add secret helper function

* adding usage, updating Chart version

---------

Co-authored-by: Jon Charette <[email protected]>
  • Loading branch information
johnnyl-harness and Jon Charette authored Jan 18, 2024
1 parent 679bad8 commit a77a32a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: library
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.5
version: 1.3.6

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
33 changes: 33 additions & 0 deletions src/common/templates/_secrets-helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,36 @@ USAGE:
{{- $localESOSecretCtxIdentifier := (include "harnesscommon.secrets.localESOSecretCtxIdentifier" (dict "ctx" $ )) }}
{{- include "harnesscommon.secrets.manageEnv" (dict "ctx" $ "variableName" .variableName "overrideEnvName" .overrideEnvName "defaultKubernetesSecretName" .defaultKubernetesSecretName "providedSecretValues" .providedSecretValues "defaultKubernetesSecretKey" .defaultKubernetesSecretKey "extKubernetesSecretCtxs" (list $.Values.secrets.kubernetesSecrets) "esoSecretCtxs" (list (dict "secretCtxIdentifier" $localESOSecretCtxIdentifier "secretCtx" $.Values.secrets.secretManagement.externalSecretsOperator))) }}
{{- end }}




{{- define "harnesscommon.secrets.generateExternalSecretRefInternal"}}
{{- $ := .ctx }}
{{- $secretNamePrefix := .secretNamePrefix }}
{{- if and .secretsCtx .secretsCtx.secretManagement .secretsCtx.secretManagement.externalSecretsOperator }}
{{- with .secretsCtx.secretManagement.externalSecretsOperator }}
{{- range $esoSecretIdx, $esoSecret := . }}
{{- if eq (include "harnesscommon.secrets.hasValidESOSecret" (dict "esoSecretCtx" .)) "true" }}
{{- $esoSecretName := (printf "%s-%d" $secretNamePrefix $esoSecretIdx) }}
- secretRef:
name: {{ $esoSecretName }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}


{{/*
Function and its warpper to add the K8S Secret created by external secret controller to serve as Env Var Ref
USAGE:
{{- include "harnesscommon.secrets.generateExternalSecretRef" . }}
*/}}
{{- define "harnesscommon.secrets.generateExternalSecretRef"}}
{{- if eq (include "harnesscommon.secrets.hasESOSecrets" (dict "secretsCtx" .Values.secrets)) "true" }}
{{- $localESOSecretIdentifier := (include "harnesscommon.secrets.localESOSecretCtxIdentifier" (dict "ctx" $ )) }}
{{- include "harnesscommon.secrets.generateExternalSecretRefInternal" (dict "secretsCtx" .Values.secrets "secretNamePrefix" $localESOSecretIdentifier) }}
{{- end }}
{{- end }}

0 comments on commit a77a32a

Please sign in to comment.