From 9bd8494e4fba870e51a99e479d975579ef83f3da Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Thu, 23 Apr 2020 16:35:21 +0800 Subject: [PATCH] fix: `common.serviceAccountName` should accepts `$serviceAccount` --- README.md | 17 ++++++++++------- templates/_cronjob.yaml | 3 ++- templates/_deployment.yaml | 3 ++- templates/_name.tpl | 5 +++-- templates/_pod.tpl | 5 +++-- templates/_serviceaccount.yaml | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4e70d6f..a693bf0 100644 --- a/README.md +++ b/README.md @@ -117,11 +117,12 @@ metadata: ### `common.cronJob` -The `common.cronJob` template accepts a list of four values: +The `common.cronJob` template accepts a list of five values: - `$top`, the top context - `$cronJob`, a dictionary of values used in the cronjob template - `$pod`, a dictionary of values used in the pod template +- `$serviceAccount`, a dictionary of values used in the service account template - [optional] the template name of the overrides It defines a basic `CronJob` with the following defaults: @@ -143,10 +144,10 @@ Underneath the hood, it invokes [`common.pod.template`](#commonpodtemplate) temp Example use: ```yaml -{{- include "common.cronJob" (list . .Values.cronJob .Values) -}} +{{- include "common.cronJob" (list . .Values.cronJob .Values .Values.serviceAccount) -}} ## The following is the same as above: -# {{- include "common.cronJob" (list . .Values.cronJob .Values "mychart.cronJob") -}} +# {{- include "common.cronJob" (list . .Values.cronJob .Values .Values.serviceAccount "mychart.cronJob") -}} # {{- define "mychart.cronJob" -}} # {{- end -}} ``` @@ -156,11 +157,12 @@ Example use: ### `common.deployment` -The `common.deployment` template accepts a list of four values: +The `common.deployment` template accepts a list of five values: - `$top`, the top context - `$deployment`, a dictionary of values used in the deployment template - `$autoscaling`, a dictionary of values used in the hpa template +- `$serviceAccount`, a dictionary of values used in the service account template - [optional] the template name of the overrides It defines a basic `Deployment` with the following settings: @@ -180,10 +182,10 @@ Underneath the hood, it invokes [`common.pod.template`](#commonpodtemplate) temp Example use: ```yaml -{{- include "common.deployment" (list . .Values .Values.autoscaling) -}} +{{- include "common.deployment" (list . .Values .Values.autoscaling .Values.serviceAccount) -}} ## The following is the same as above: -# {{- include "common.deployment" (list . .Values .Values.autoscaling "mychart.deployment") -}} +# {{- include "common.deployment" (list . .Values .Values.autoscaling .Values.serviceAccount "mychart.deployment") -}} # {{- define "mychart.deployment" -}} # {{- end -}} ``` @@ -1012,10 +1014,11 @@ Output of this function is truncated at 63 characters, which is the maximum leng ### `common.pod.template` -The `common.pod.template` template accepts a list of three values: +The `common.pod.template` template accepts a list of four values: - `$top`, the top context - `$pod`, a dictionary of values used in the container template +- `$serviceAccount`, a dictionary of values used in the service account template - [optional] the template name of the overrides It creates a basic `PodTemplate` spec to be used within a `Deployment` or `CronJob`. It holds the following defaults: diff --git a/templates/_cronjob.yaml b/templates/_cronjob.yaml index 6aec3a1..4864d5e 100644 --- a/templates/_cronjob.yaml +++ b/templates/_cronjob.yaml @@ -9,6 +9,7 @@ spec: {{- $top := first . -}} {{- $cronJob := index . 1 -}} {{- $pod := index . 2 -}} +{{- $serviceAccount := index . 3 -}} apiVersion: batch/v1beta1 kind: CronJob metadata: @@ -30,7 +31,7 @@ spec: {{- include "common.selectorLabels" $top | nindent 8 }} spec: template: - {{- include "common.pod.template" (list $top $pod "common.cronJob.pod") | nindent 8 }} + {{- include "common.pod.template" (list $top $pod $serviceAccount "common.cronJob.pod") | nindent 8 }} {{- end -}} {{- define "common.cronJob" -}} diff --git a/templates/_deployment.yaml b/templates/_deployment.yaml index 0f6e9ae..b26f079 100644 --- a/templates/_deployment.yaml +++ b/templates/_deployment.yaml @@ -4,6 +4,7 @@ {{- $top := first . -}} {{- $deployment := index . 1 -}} {{- $autoscaling := index . 2 -}} +{{- $serviceAccount := index . 3 -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -16,7 +17,7 @@ spec: matchLabels: {{- include "common.selectorLabels" $top | nindent 6 }} template: - {{- include "common.pod.template" . | nindent 4 }} + {{- include "common.pod.template" (list $top $deployment $serviceAccount) | nindent 4 }} {{- end -}} {{- define "common.deployment" -}} diff --git a/templates/_name.tpl b/templates/_name.tpl index 4c27502..9e6d873 100644 --- a/templates/_name.tpl +++ b/templates/_name.tpl @@ -36,9 +36,10 @@ Create chart name and version as used by the chart label. Create the name of the service account to use. */}} {{- define "common.serviceAccountName" -}} -{{- $serviceAccount := .Values.serviceAccount | default (dict) -}} +{{- $top := first . -}} +{{- $serviceAccount := index . 1 -}} {{- if $serviceAccount.create -}} - {{ default (include "common.fullname" .) $serviceAccount.name }} + {{ default (include "common.fullname" $top) $serviceAccount.name }} {{- else -}} {{ default "default" $serviceAccount.name }} {{- end -}} diff --git a/templates/_pod.tpl b/templates/_pod.tpl index 12a048e..72d4c7c 100644 --- a/templates/_pod.tpl +++ b/templates/_pod.tpl @@ -3,6 +3,7 @@ {{- define "common.pod.template.tpl" -}} {{- $top := first . -}} {{- $pod := index . 1 -}} +{{- $serviceAccount := index . 2 -}} metadata: labels: {{- include "common.selectorLabels" $top | nindent 4 }} @@ -11,11 +12,11 @@ spec: imagePullSecrets: {{- toYaml . | nindent 4 }} {{- end }} - serviceAccountName: {{ include "common.serviceAccountName" $top }} + serviceAccountName: {{ include "common.serviceAccountName" (list $top $serviceAccount) }} securityContext: {{- toYaml $pod.podSecurityContext | nindent 4 }} containers: - - {{- include "common.container" . | nindent 6 }} + - {{- include "common.container" (list $top $pod) | nindent 6 }} {{- with $pod.nodeSelector }} nodeSelector: {{- toYaml . | nindent 4 }} diff --git a/templates/_serviceaccount.yaml b/templates/_serviceaccount.yaml index 82b79ab..ff0c9bb 100644 --- a/templates/_serviceaccount.yaml +++ b/templates/_serviceaccount.yaml @@ -3,7 +3,7 @@ {{- define "common.serviceAccount.metadata" -}} {{- $top := first . -}} {{- $serviceAccount := index . 1 -}} -name: {{ include "common.serviceAccountName" $top }} +name: {{ include "common.serviceAccountName" . }} {{- with $serviceAccount.annotations }} annotations: {{- toYaml . | nindent 2 }}