Commit 014a7c97 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Merge branch 'add-support-for-service-account-creation' into 'master'

Add support for service account creation

Closes #159

See merge request gitlab-org/cluster-integration/auto-deploy-image!192
parents 2bb80c5b fff74f76
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
apiVersion: v1
description: GitLab's Auto-deploy Helm Chart
name: auto-deploy-app
version: 2.9.0
version: 2.10.0
icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png
+4 −1
Original line number Diff line number Diff line
@@ -10,7 +10,10 @@
| ---                           | ---         | ---                                |
| replicaCount                  |             | `1`                                |
| strategyType                  | Pod deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) | `nil` |
| serviceAccountName            | Pod service account name override  | `nil` |
| serviceAccountName(**DEPRECATED**)            | Pod service account name override  | `nil` |
| serviceAccount.name           | Name of service account to use for running the pods | `nil` |
| serviceAccount.createNew      | If set to `true`, a new service account will be created with the details specified in the other fields under `serviceAccount`. If set to `false`, the service account specified in `serviceAccount.name` is expected to already exist. | `false` |
| serviceAccount.annotations    | Annotations for the service account to be created | `nil` |
| image.repository              |             | `gitlab.example.com/group/project` |
| image.tag                     |             | `stable`                           |
| image.pullPolicy              |             | `Always`                           |
+2 −2
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ spec:
        tier: "{{ .Values.application.tier }}"
{{ include "sharedlabels" . | indent 8 }}
    spec:
{{- if .Values.serviceAccountName }}
      serviceAccountName: {{ .Values.serviceAccountName | quote }}
{{- if or (.Values.serviceAccount.name) (.Values.serviceAccountName) }}
      serviceAccountName: {{ .Values.serviceAccount.name | default .Values.serviceAccountName | quote }}
{{- end }}
      imagePullSecrets:
{{ toYaml .Values.image.secrets | indent 10 }}
+12 −0
Original line number Diff line number Diff line
{{- with .Values.serviceAccount -}}
{{- if .createNew }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ .name | quote }}
{{- if .annotations }}
  annotations:
{{ toYaml .annotations | indent 4 }}
{{- end }}
{{- end }}
{{- end -}}
+70 −0
Original line number Diff line number Diff line
@@ -172,6 +172,7 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

	// serviceAccountName
	for _, tc := range []struct {
		CaseName                   string
		Release                    string
@@ -224,6 +225,75 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

	// serviceAccount
	for _, tc := range []struct {
		CaseName string
		Release  string
		Values   map[string]string

		ExpectedServiceAccountName string
	}{
		{
			CaseName:                   "default service account",
			Release:                    "production",
			ExpectedServiceAccountName: "",
		},
		{
			CaseName: "empty service account name",
			Release:  "production",
			Values: map[string]string{
				"serviceAccount.name": "",
			},
			ExpectedServiceAccountName: "",
		},
		{
			CaseName: "custom service account name - myServiceAccount",
			Release:  "production",
			Values: map[string]string{
				"serviceAccount.name": "myServiceAccount",
			},
			ExpectedServiceAccountName: "myServiceAccount",
		},
		{
			CaseName: "serviceAccount.name takes precedence over serviceAccountName",
			Release:  "production",
			Values: map[string]string{
				"serviceAccount.name": "myServiceAccount1",
				"serviceAccountName":  "myServiceAccount2",
			},
			ExpectedServiceAccountName: "myServiceAccount1",
		},
	} {
		t.Run(tc.CaseName, func(t *testing.T) {
			namespaceName := "minimal-ruby-app-" + strings.ToLower(random.UniqueId())

			values := map[string]string{
				"gitlab.app": "auto-devops-examples/minimal-ruby-app",
				"gitlab.env": "prod",
			}

			mergeStringMap(values, tc.Values)

			options := &helm.Options{
				SetValues:      values,
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output := helm.RenderTemplate(
				t,
				options,
				helmChartPath,
				tc.Release,
				[]string{"templates/deployment.yaml"},
			)

			var deployment appsV1.Deployment
			helm.UnmarshalK8SYaml(t, output, &deployment)

			require.Equal(t, tc.ExpectedServiceAccountName, deployment.Spec.Template.Spec.ServiceAccountName)
		})
	}

	// deployment lifecycle
	for _, tc := range []struct {
		CaseName string
Loading