Commit 7ce71568 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason
Browse files

Merge branch 'walkafwalka/auto-deploy-image-lifecycle' into 'master'

feat: support deployment and worker lifecycles

See merge request gitlab-org/cluster-integration/auto-deploy-image!195
parents ac8b8d20 592a818c
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.7.0
version: 2.8.0
icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
| image.pullPolicy              |             | `Always`                           |
| image.secrets                 |             | `[name: gitlab-registry]`          |
| extraLabels                   | Allow labelling resources with custom key/value pairs | `{}` |
| lifecycle                     | [Container lifecycle hooks](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/) | `{}` |
| podAnnotations                | Pod annotations | `{}`                           |
| nodeSelector                  | Node labels for pod assignment | `{}`           |
| tolerations                   | List of node taints to tolerate | `[]`          |
+4 −0
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ spec:
          value: {{ .Values.gitlab.envName | quote }}
        - name: GITLAB_ENVIRONMENT_URL
          value: {{ .Values.gitlab.envURL | quote }}
{{- if .Values.lifecycle }}
        lifecycle:
{{ toYaml .Values.lifecycle | indent 10 }}
{{- end }}
        ports:
        - name: "{{ .Values.service.name }}"
          containerPort: {{ .Values.service.internalPort }}
+6 −1
Original line number Diff line number Diff line
@@ -120,8 +120,12 @@ items:
            timeoutSeconds: {{ $readinessProbeConfig.timeoutSeconds }}
{{- end }}
{{- end }}
          {{- if $workerConfig.preStopCommand }}
          {{- if or $workerConfig.lifecycle $workerConfig.preStopCommand }}
          lifecycle:
          {{- if $workerConfig.lifecycle }}
{{ toYaml $workerConfig.lifecycle | indent 12 }}
          {{- end }}
            {{- if $workerConfig.preStopCommand }}
            preStop:
              exec:
                command:
@@ -129,6 +133,7 @@ items:
                - {{ . }}
                {{- end }}
            {{- end}}
          {{- end }}
          resources:
{{ toYaml $.Values.resources | indent 12 }}
{{- end -}}
+49 −0
Original line number Diff line number Diff line
@@ -223,6 +223,55 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

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

		ExpectedLifecycle *coreV1.Lifecycle
	}{
		{
			CaseName:          "lifecycle",
			Release:           "production",
			Values: map[string]string{
				"lifecycle.preStop.exec.command[0]": "/bin/sh",
				"lifecycle.preStop.exec.command[1]": "-c",
				"lifecycle.preStop.exec.command[2]": "sleep 10",
			},
			ExpectedLifecycle: &coreV1.Lifecycle{
				PreStop: &coreV1.Handler{
					Exec: &coreV1.ExecAction{
						Command: []string{"/bin/sh", "-c", "sleep 10"},
					},
				},
			},
		},
	} {
		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.ExpectedLifecycle, deployment.Spec.Template.Spec.Containers[0].Lifecycle)
		})
	}

	// deployment livenessProbe, and readinessProbe tests
	for _, tc := range []struct {
		CaseName string
Loading