mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-04 08:57:04 +02:00
feat(common): Release 3.5.0 (#357)
Co-authored-by: Lawrence Gil <lawrence.gil@assemblyglobal.com>
This commit is contained in:
parent
5a722abfa9
commit
90e6b9e7cf
42 changed files with 1092 additions and 164 deletions
|
@ -1,15 +1,17 @@
|
|||
{{/*
|
||||
Convert configMap values to an object
|
||||
Convert values to an object
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.configMap.valuesToObject" -}}
|
||||
{{- define "bjw-s.common.lib.valuesToObject" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Determine and inject the configMap name */ -}}
|
||||
{{- /* Determine and inject the name */ -}}
|
||||
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
{{- if $objectValues.nameOverride -}}
|
||||
{{- if $objectValues.forceRename -}}
|
||||
{{- $objectName = tpl $objectValues.forceRename $rootContext -}}
|
||||
{{- else if $objectValues.nameOverride -}}
|
||||
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
|
||||
{{- if not (eq $objectName $override) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $override -}}
|
||||
|
@ -19,9 +21,9 @@ Convert configMap values to an object
|
|||
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $_ := set $objectValues "name" $objectName -}}
|
||||
{{- $_ := set $objectValues "identifier" $identifier -}}
|
||||
|
||||
{{- /* Return the configMap object */ -}}
|
||||
{{- /* Return the object */ -}}
|
||||
{{- $objectValues | toYaml -}}
|
||||
{{- end -}}
|
|
@ -7,6 +7,6 @@ Return a configMap Object by its Identifier.
|
|||
|
||||
{{- $configMapValues := dig $identifier nil $rootContext.Values.configMaps -}}
|
||||
{{- if not (empty $configMapValues) -}}
|
||||
{{- include "bjw-s.common.lib.configMap.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $configMapValues) -}}
|
||||
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $configMapValues) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -4,4 +4,8 @@ Validate configMap values
|
|||
{{- define "bjw-s.common.lib.configMap.validate" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $configMapValues := .object -}}
|
||||
|
||||
{{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}}
|
||||
{{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -3,9 +3,21 @@ Returns the value for serviceAccountName
|
|||
*/ -}}
|
||||
{{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}}
|
||||
{{- $rootContext := .ctx.rootContext -}}
|
||||
{{- $controllerObject := .ctx.controllerObject -}}
|
||||
|
||||
{{- $serviceAccountValues := (mustDeepCopy $rootContext.Values.serviceAccount) -}}
|
||||
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
|
||||
{{- $serviceAccountObject.name -}}
|
||||
{{- $serviceAccountName := "default" -}}
|
||||
|
||||
{{- if (get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "create") -}}
|
||||
{{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "name" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $controllerObject.serviceAccount -}}
|
||||
{{- if hasKey . "identifier" -}}
|
||||
{{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml) "name" -}}
|
||||
{{- else if hasKey . "name" -}}
|
||||
{{- $serviceAccountName = .name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $serviceAccountName -}}
|
||||
|
||||
{{- end -}}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
{{/*
|
||||
Convert raw resource values to an object
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.rawResource.valuesToObject" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Determine and inject the raw resource name */ -}}
|
||||
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
{{- if $objectValues.nameOverride -}}
|
||||
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
|
||||
{{- if not (eq $objectName $override) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $override -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if not (eq $objectName $identifier) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $_ := set $objectValues "name" $objectName -}}
|
||||
{{- $_ := set $objectValues "identifier" $identifier -}}
|
||||
|
||||
{{- /* Return the raw resource object */ -}}
|
||||
{{- $objectValues | toYaml -}}
|
||||
{{- end -}}
|
|
@ -0,0 +1,12 @@
|
|||
{{/*
|
||||
Return a Role Object by its Identifier.
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.rbac.role.getByIdentifier" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
|
||||
{{- $roleValues := dig $identifier nil $rootContext.Values.rbac.roles -}}
|
||||
{{- if not (empty $roleValues) -}}
|
||||
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleValues) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
18
charts/library/common/templates/lib/role/_validate.tpl
Normal file
18
charts/library/common/templates/lib/role/_validate.tpl
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{/*
|
||||
Validate Role values
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.rbac.role.validate" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $roleValues := .object -}}
|
||||
{{- $type := required "The role needs to have an explicitly declared type" $roleValues.type -}}
|
||||
{{- $typeList := list "Role" "ClusterRole" -}}
|
||||
{{- $rules := $roleValues.rules -}}
|
||||
|
||||
{{- if not (mustHas $type $typeList) -}}
|
||||
{{- fail (printf "You selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- end -}}
|
||||
{{- if not $rules -}}
|
||||
{{- fail "Rules can't be empty" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
|
@ -0,0 +1,12 @@
|
|||
{{/*
|
||||
Return a RoleBinding Object by its Identifier.
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.rbac.roleBinding.getByIdentifier" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
|
||||
{{- $roleBindingValues := dig $identifier nil $rootContext.Values.rbac.bindings -}}
|
||||
{{- if not (empty $roleBindingValues) -}}
|
||||
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleBindingValues) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
|
@ -0,0 +1,32 @@
|
|||
{{/*
|
||||
Validate RoleBinding values
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.rbac.roleBinding.validate" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $roleBindingValues := .object -}}
|
||||
{{- $type := required "The binding needs to have an explicitly declared type" $roleBindingValues.type -}}
|
||||
{{- $typeList := list "RoleBinding" "ClusterRoleBinding" -}}
|
||||
{{- $subjects := $roleBindingValues.subjects -}}
|
||||
{{- $roleRef := required "A roleRef is required" $roleBindingValues.roleRef -}}
|
||||
|
||||
{{- if not (mustHas $type $typeList) -}}
|
||||
{{- fail (printf "You selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (hasKey $roleRef "identifier") -}}
|
||||
{{- $name := required "If not using identifier roleRef must have a `name` key" $roleRef.name -}}
|
||||
{{- $name := required "If not using identifier roleRef must have a `kind` key" $roleRef.kind -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $subject := $subjects -}}
|
||||
{{- if not (hasKey . "identifier") -}}
|
||||
{{- if not (hasKey . "name") -}}
|
||||
{{- $name := required "If not using identifier a subject must have a `name` key" .name -}}
|
||||
{{- else if not (hasKey . "namespace") -}}
|
||||
{{- $namespace := required "If not using identifier a subject must have a `namespace` key" .namespace -}}
|
||||
{{- else if not (hasKey . "kind") -}}
|
||||
{{- $kind := required "If not using identifier a subject must have a `kind` key" .kind -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
|
@ -7,6 +7,6 @@ Return a secret Object by its Identifier.
|
|||
|
||||
{{- $secretValues := dig $identifier nil $rootContext.Values.secrets -}}
|
||||
{{- if not (empty $secretValues) -}}
|
||||
{{- include "bjw-s.common.lib.secret.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $secretValues) -}}
|
||||
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $secretValues) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
{{/*
|
||||
Convert Secret values to an object
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.secret.valuesToObject" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Determine and inject the Secret name */ -}}
|
||||
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
{{- if $objectValues.nameOverride -}}
|
||||
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
|
||||
{{- if not (eq $objectName $override) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $override -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if not (eq $objectName $identifier) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $_ := set $objectValues "name" $objectName -}}
|
||||
{{- $_ := set $objectValues "identifier" $identifier -}}
|
||||
|
||||
{{- /* Return the Secret object */ -}}
|
||||
{{- $objectValues | toYaml -}}
|
||||
{{- end -}}
|
|
@ -0,0 +1,17 @@
|
|||
{{/*
|
||||
Return a ServiceAccount Object by its Identifier.
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.serviceAccount.getByIdentifier" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $identifier := .id -}}
|
||||
{{- if eq $identifier "default" -}}
|
||||
{{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $rootContext.Values.serviceAccount) -}}
|
||||
{{- else -}}
|
||||
{{- $serviceAccountValues := dig "extraServiceAccounts" $identifier nil $rootContext.Values.serviceAccount -}}
|
||||
{{- if not (empty $serviceAccountValues) -}}
|
||||
{{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceAccountValues) -}}
|
||||
{{- else -}}
|
||||
{{- fail (printf "No ServiceAccount configured with identifier: %s" $identifier) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
|
@ -7,17 +7,19 @@ Convert ServiceAccount values to an object
|
|||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Determine and inject the serviceAccount name */ -}}
|
||||
{{- $serviceAccountName := "" -}}
|
||||
{{- $defaultServiceAccountName := "default" -}}
|
||||
{{- if $objectValues.create -}}
|
||||
{{- $defaultServiceAccountName = (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
{{- $defaultServiceAccountName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
{{- $objectName := $defaultServiceAccountName -}}
|
||||
|
||||
{{- with $objectValues.name -}}
|
||||
{{- $objectName = . -}}
|
||||
{{- end -}}
|
||||
{{- if and (ne $identifier "default") (not $objectValues.name) -}}
|
||||
{{- $objectName = printf "%s-%s" $defaultServiceAccountName $identifier -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $serviceAccountName = default $defaultServiceAccountName $objectValues.name -}}
|
||||
|
||||
{{- $_ := set $objectValues "name" $serviceAccountName -}}
|
||||
{{- $_ := set $objectValues "name" $objectName -}}
|
||||
{{- $_ := set $objectValues "identifier" $identifier -}}
|
||||
|
||||
{{- /* Return the serviceAccount object */ -}}
|
||||
{{- $objectValues | toYaml -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue