fix: common.serviceAccountName should accepts $serviceAccount

This commit is contained in:
Chi-En Wu
2020-04-23 16:35:21 +08:00
parent b5cae82278
commit 9bd8494e4f
6 changed files with 21 additions and 14 deletions

View File

@ -117,11 +117,12 @@ metadata:
### `common.cronJob` ### `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 - `$top`, the top context
- `$cronJob`, a dictionary of values used in the cronjob template - `$cronJob`, a dictionary of values used in the cronjob template
- `$pod`, a dictionary of values used in the pod 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 - [optional] the template name of the overrides
It defines a basic `CronJob` with the following defaults: 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: Example use:
```yaml ```yaml
{{- include "common.cronJob" (list . .Values.cronJob .Values) -}} {{- include "common.cronJob" (list . .Values.cronJob .Values .Values.serviceAccount) -}}
## The following is the same as above: ## 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" -}} # {{- define "mychart.cronJob" -}}
# {{- end -}} # {{- end -}}
``` ```
@ -156,11 +157,12 @@ Example use:
### `common.deployment` ### `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 - `$top`, the top context
- `$deployment`, a dictionary of values used in the deployment template - `$deployment`, a dictionary of values used in the deployment template
- `$autoscaling`, a dictionary of values used in the hpa 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 - [optional] the template name of the overrides
It defines a basic `Deployment` with the following settings: 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: Example use:
```yaml ```yaml
{{- include "common.deployment" (list . .Values .Values.autoscaling) -}} {{- include "common.deployment" (list . .Values .Values.autoscaling .Values.serviceAccount) -}}
## The following is the same as above: ## 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" -}} # {{- define "mychart.deployment" -}}
# {{- end -}} # {{- end -}}
``` ```
@ -1012,10 +1014,11 @@ Output of this function is truncated at 63 characters, which is the maximum leng
### `common.pod.template` ### `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 - `$top`, the top context
- `$pod`, a dictionary of values used in the container template - `$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 - [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: It creates a basic `PodTemplate` spec to be used within a `Deployment` or `CronJob`. It holds the following defaults:

View File

@ -9,6 +9,7 @@ spec:
{{- $top := first . -}} {{- $top := first . -}}
{{- $cronJob := index . 1 -}} {{- $cronJob := index . 1 -}}
{{- $pod := index . 2 -}} {{- $pod := index . 2 -}}
{{- $serviceAccount := index . 3 -}}
apiVersion: batch/v1beta1 apiVersion: batch/v1beta1
kind: CronJob kind: CronJob
metadata: metadata:
@ -30,7 +31,7 @@ spec:
{{- include "common.selectorLabels" $top | nindent 8 }} {{- include "common.selectorLabels" $top | nindent 8 }}
spec: spec:
template: 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 -}} {{- end -}}
{{- define "common.cronJob" -}} {{- define "common.cronJob" -}}

View File

@ -4,6 +4,7 @@
{{- $top := first . -}} {{- $top := first . -}}
{{- $deployment := index . 1 -}} {{- $deployment := index . 1 -}}
{{- $autoscaling := index . 2 -}} {{- $autoscaling := index . 2 -}}
{{- $serviceAccount := index . 3 -}}
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -16,7 +17,7 @@ spec:
matchLabels: matchLabels:
{{- include "common.selectorLabels" $top | nindent 6 }} {{- include "common.selectorLabels" $top | nindent 6 }}
template: template:
{{- include "common.pod.template" . | nindent 4 }} {{- include "common.pod.template" (list $top $deployment $serviceAccount) | nindent 4 }}
{{- end -}} {{- end -}}
{{- define "common.deployment" -}} {{- define "common.deployment" -}}

View File

@ -36,9 +36,10 @@ Create chart name and version as used by the chart label.
Create the name of the service account to use. Create the name of the service account to use.
*/}} */}}
{{- define "common.serviceAccountName" -}} {{- define "common.serviceAccountName" -}}
{{- $serviceAccount := .Values.serviceAccount | default (dict) -}} {{- $top := first . -}}
{{- $serviceAccount := index . 1 -}}
{{- if $serviceAccount.create -}} {{- if $serviceAccount.create -}}
{{ default (include "common.fullname" .) $serviceAccount.name }} {{ default (include "common.fullname" $top) $serviceAccount.name }}
{{- else -}} {{- else -}}
{{ default "default" $serviceAccount.name }} {{ default "default" $serviceAccount.name }}
{{- end -}} {{- end -}}

View File

@ -3,6 +3,7 @@
{{- define "common.pod.template.tpl" -}} {{- define "common.pod.template.tpl" -}}
{{- $top := first . -}} {{- $top := first . -}}
{{- $pod := index . 1 -}} {{- $pod := index . 1 -}}
{{- $serviceAccount := index . 2 -}}
metadata: metadata:
labels: labels:
{{- include "common.selectorLabels" $top | nindent 4 }} {{- include "common.selectorLabels" $top | nindent 4 }}
@ -11,11 +12,11 @@ spec:
imagePullSecrets: imagePullSecrets:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}
{{- end }} {{- end }}
serviceAccountName: {{ include "common.serviceAccountName" $top }} serviceAccountName: {{ include "common.serviceAccountName" (list $top $serviceAccount) }}
securityContext: securityContext:
{{- toYaml $pod.podSecurityContext | nindent 4 }} {{- toYaml $pod.podSecurityContext | nindent 4 }}
containers: containers:
- {{- include "common.container" . | nindent 6 }} - {{- include "common.container" (list $top $pod) | nindent 6 }}
{{- with $pod.nodeSelector }} {{- with $pod.nodeSelector }}
nodeSelector: nodeSelector:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}

View File

@ -3,7 +3,7 @@
{{- define "common.serviceAccount.metadata" -}} {{- define "common.serviceAccount.metadata" -}}
{{- $top := first . -}} {{- $top := first . -}}
{{- $serviceAccount := index . 1 -}} {{- $serviceAccount := index . 1 -}}
name: {{ include "common.serviceAccountName" $top }} name: {{ include "common.serviceAccountName" . }}
{{- with $serviceAccount.annotations }} {{- with $serviceAccount.annotations }}
annotations: annotations:
{{- toYaml . | nindent 2 }} {{- toYaml . | nindent 2 }}