Skip to content

Commit fcfd885

Browse files
authored
check existence of sa in helm templates (#1939)
1 parent 9682273 commit fcfd885

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

kubernetes/charts/weblogic-operator/templates/_utils.tpl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,19 @@ Verify that a list of strings can not be defined if another string is already de
457457
*/}}
458458
{{- define "utils.mutexString" -}}
459459
{{- include "utils.mutexValue" (append . "string") -}}
460-
{{- end -}}
460+
{{- end -}}
461+
462+
{{/*
463+
Verify that a Kubernetes resource exists in a given namespace
464+
*/}}
465+
{{- define "utils.verifyK8SResource" -}}
466+
{{- $scope := index . 0 -}}
467+
{{- $name := index . 1 -}}
468+
{{- $type := index . 2 -}}
469+
{{- $namespace := index . 3 -}}
470+
{{- $found := (lookup "v1" $type $namespace $name) }}
471+
{{- if not $found }}
472+
{{- $errorMsg := cat $type $name " does not exist in namespace " $namespace -}}
473+
{{- include "utils.recordValidationError" (list $scope $errorMsg) -}}
474+
{{- end -}}
475+
{{- end -}}

kubernetes/charts/weblogic-operator/templates/_validate-inputs.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{{- $ignore := include "utils.verifyResourceName" (list $scope "Namespace") -}}
99
{{- $ignore := include "utils.popValidationContext" $scope -}}
1010
{{- $ignore := include "utils.verifyString" (list $scope "serviceAccount") -}}
11+
{{- $ignore := include "utils.verifyK8SResource" (list $scope .serviceAccount "ServiceAccount" .Release.Namespace) -}}
1112
{{- $ignore := include "utils.verifyString" (list $scope "image") -}}
1213
{{- $ignore := include "utils.verifyEnum" (list $scope "imagePullPolicy" (list "Always" "IfNotPresent" "Never")) -}}
1314
{{- $ignore := include "utils.verifyOptionalDictionaryList" (list $scope "imagePullSecrets") -}}

0 commit comments

Comments
 (0)