Skip to content

Commit

Permalink
fix: use string checks for boolean expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesimpson36 committed May 31, 2024
1 parent 512aaa7 commit 5743c75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 13 additions & 5 deletions null_checking_bug/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
{{- define "null_checking_bug.isPasswordExplicit" -}}
{{- typeIs "string" .Values.existingSecret -}}
{{- if typeIs "string" .Values.existingSecret -}}
true
{{- else -}}
false
{{- end -}}
{{- end -}}

{{- define "null_checking_bug.isSecretName" -}}
{{- and (typeIs "map[string]interface {}" .Values.existingSecret)
{{- if and (typeIs "map[string]interface {}" .Values.existingSecret)
(get .Values.existingSecret "name") -}}
true
{{- else -}}
false
{{- end -}}
{{- end -}}


{{- define "null_checking_bug.evaluateNameOfSecret" -}}
{{- if (include "null_checking_bug.isPasswordExplicit" .) -}}
{{- if eq "true" (include "null_checking_bug.isPasswordExplicit" .) -}}
"default-secret"
{{- else if (include "null_checking_bug.isSecretName" .) -}}
{{- .Values.existingSecret.name | default "default-secret" }}
{{- else if eq "true" (include "null_checking_bug.isSecretName" .) -}}
{{- .Values.existingSecret.name | default "replace-default-secret" | quote }}
{{- end }}
{{- end -}}
3 changes: 0 additions & 3 deletions null_checking_bug/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ data:
isSecretName: {{ (include "null_checking_bug.isSecretName" .) | quote }}
isPasswordExplicit: {{ (include "null_checking_bug.isPasswordExplicit" .) | quote }}
nameOfSecret: {{ include "null_checking_bug.evaluateNameOfSecret" . }}
{{- if (include "null_checking_bug.isSecretName" .) -}}
nameOfSecretFromValuesYaml: {{ .Values.existingSecret.name }}
{{- end }}
typeOfSecretName: {{ typeOf (include "null_checking_bug.isSecretName" .) | quote }}
kind: Secret
metadata:
Expand Down

0 comments on commit 5743c75

Please sign in to comment.