diff --git a/charts/podinfo/README.md b/charts/podinfo/README.md index 05e4c3e..1ad3eeb 100644 --- a/charts/podinfo/README.md +++ b/charts/podinfo/README.md @@ -63,6 +63,8 @@ Parameter | Description | Default `service.nodePort` | node port for the service | `31198` `service.type` | type of service | `ClusterIP` `tolerations` | list of node taints to tolerate | `[]` +`serviceAccount.create` | specifies whether a service account should be created | `false` +`serviceAccount.name` | the name of the service account to use, if not set and create is true, a name is generated using the fullname template | None Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/charts/podinfo/templates/_helpers.tpl b/charts/podinfo/templates/_helpers.tpl index ef88d3d..62e6e12 100644 --- a/charts/podinfo/templates/_helpers.tpl +++ b/charts/podinfo/templates/_helpers.tpl @@ -30,3 +30,14 @@ Create chart name and version as used by the chart label. {{- define "podinfo.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "podinfo.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "podinfo.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/podinfo/templates/deployment.yaml b/charts/podinfo/templates/deployment.yaml index f70a728..1d0189f 100644 --- a/charts/podinfo/templates/deployment.yaml +++ b/charts/podinfo/templates/deployment.yaml @@ -26,6 +26,9 @@ spec: prometheus.io/scrape: 'true' spec: terminationGracePeriodSeconds: 30 + {{- if .Values.serviceAccount.create }} + serviceAccountName: {{ template "podinfo.serviceAccountName" . }} + {{- end }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" diff --git a/charts/podinfo/templates/serviceaccount.yaml b/charts/podinfo/templates/serviceaccount.yaml new file mode 100644 index 0000000..7d398bf --- /dev/null +++ b/charts/podinfo/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "podinfo.serviceAccountName" . }} + labels: + app: {{ template "podinfo.name" . }} + chart: {{ template "podinfo.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{- end -}} diff --git a/charts/podinfo/values.yaml b/charts/podinfo/values.yaml index 0d1d3b9..ef3fd1c 100644 --- a/charts/podinfo/values.yaml +++ b/charts/podinfo/values.yaml @@ -33,6 +33,13 @@ hpa: # average http requests per second per pod (k8s-prometheus-adapter) requests: +serviceAccount: + # Specifies whether a service account should be created + create: false + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: + ingress: enabled: false annotations: {}