Unverified Commit 6c88a429 authored by Matt Farina's avatar Matt Farina Committed by GitHub

Merge pull request #5890 from naseemkullah/sa

[helm create] Add service account to templates
parents 3630a532 ab8585fa
...@@ -143,7 +143,7 @@ func TestCreateStarterCmd(t *testing.T) { ...@@ -143,7 +143,7 @@ func TestCreateStarterCmd(t *testing.T) {
t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion) t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion)
} }
expectedTemplateCount := 7 expectedTemplateCount := 8
if l := len(c.Templates); l != expectedTemplateCount { if l := len(c.Templates); l != expectedTemplateCount {
t.Errorf("Expected %d templates, got %d", expectedTemplateCount, l) t.Errorf("Expected %d templates, got %d", expectedTemplateCount, l)
} }
......
...@@ -42,6 +42,8 @@ const ( ...@@ -42,6 +42,8 @@ const (
DeploymentName = "deployment.yaml" DeploymentName = "deployment.yaml"
// ServiceName is the name of the example service file. // ServiceName is the name of the example service file.
ServiceName = "service.yaml" ServiceName = "service.yaml"
// ServiceAccountName is the name of the example serviceaccount file.
ServiceAccountName = "serviceaccount.yaml"
// NotesName is the name of the example NOTES.txt file. // NotesName is the name of the example NOTES.txt file.
NotesName = "NOTES.txt" NotesName = "NOTES.txt"
// HelpersName is the name of the example helpers file. // HelpersName is the name of the example helpers file.
...@@ -67,6 +69,13 @@ imagePullSecrets: [] ...@@ -67,6 +69,13 @@ imagePullSecrets: []
nameOverride: "" nameOverride: ""
fullnameOverride: "" fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: true
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name:
service: service:
type: ClusterIP type: ClusterIP
port: 80 port: 80
...@@ -189,6 +198,7 @@ spec: ...@@ -189,6 +198,7 @@ spec:
imagePullSecrets: imagePullSecrets:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
serviceAccountName: {{ template "<CHARTNAME>.serviceAccountName" . }}
containers: containers:
- name: {{ .Chart.Name }} - name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
...@@ -238,6 +248,15 @@ spec: ...@@ -238,6 +248,15 @@ spec:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
` `
const defaultServiceAccount = `{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "<CHARTNAME>.serviceAccountName" . }}
labels:
{{ include "<CHARTNAME>.labels" . | indent 4 }}
{{- end -}}
`
const defaultNotes = `1. Get the application URL by running these commands: const defaultNotes = `1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }} {{- if .Values.ingress.enabled }}
...@@ -307,6 +326,17 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} ...@@ -307,6 +326,17 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }} {{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}} {{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "<CHARTNAME>.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "<CHARTNAME>.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
` `
const defaultTestConnection = `apiVersion: v1 const defaultTestConnection = `apiVersion: v1
...@@ -425,6 +455,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) { ...@@ -425,6 +455,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
path: filepath.Join(cdir, TemplatesDir, ServiceName), path: filepath.Join(cdir, TemplatesDir, ServiceName),
content: Transform(defaultService, "<CHARTNAME>", chartfile.Name), content: Transform(defaultService, "<CHARTNAME>", chartfile.Name),
}, },
{
// serviceaccount.yaml
path: filepath.Join(cdir, TemplatesDir, ServiceAccountName),
content: Transform(defaultServiceAccount, "<CHARTNAME>", chartfile.Name),
},
{ {
// NOTES.txt // NOTES.txt
path: filepath.Join(cdir, TemplatesDir, NotesName), path: filepath.Join(cdir, TemplatesDir, NotesName),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment