Commit 9b9ef542 authored by Thong Kuah's avatar Thong Kuah
Browse files

BREAKING CHANGE: Deployment now uses apps/v1

Removes deploymentApiVersion setting. Deployment is now apps/v1
Also removes enableSelector, as we must always have selector now.
parent 2de94cac
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.0.0-beta.3
version: 2.0.0-beta.4
icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png
+1 −3
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ If you have any questions, please ask in <https://gitlab.com/gitlab-org/charts/a
| ---                           | ---         | ---                                |
| replicaCount                  |             | `1`                                |
| strategyType                  | Pod deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) | `nil` |
| enableSelector                | If `true`, enables selector field for the deployment. Only applicable for `extensions/v1beta1`, as selector field will always be included for `apps/v1` | `nil` |
| deploymentApiVersion          | Sets `apiVersion` field for the deployment. Can be set to either `extensions/v1beta1` or `apps/v1`. | `extensions/v1beta1` |
| image.repository              |             | `gitlab.example.com/group/project` |
| image.tag                     |             | `stable`                           |
| image.pullPolicy              |             | `Always`                           |
+1 −3
Original line number Diff line number Diff line
{{- if not .Values.application.initializeCommand -}}
apiVersion: {{ default "extensions/v1beta1" .Values.deploymentApiVersion }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "trackableappname" . }}
@@ -14,14 +14,12 @@ metadata:
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
{{- if or .Values.enableSelector (eq (default "extensions/v1beta1" .Values.deploymentApiVersion) "apps/v1") }}
  selector:
    matchLabels:
      app: {{ template "appname" . }}
      track: "{{ .Values.application.track }}"
      tier: "{{ .Values.application.tier }}"
      release: {{ .Release.Name }}
{{- end }}
  replicas: {{ .Values.replicaCount }}
{{- if .Values.strategyType }}
  strategy:
+1 −3
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ apiVersion: v1
kind: List
items:
{{- range $workerName, $workerConfig :=  .Values.workers }}
- apiVersion: {{ default "extensions/v1beta1" $.Values.deploymentApiVersion }}
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: {{ template "trackableappname" $ }}-{{ $workerName }}
@@ -17,13 +17,11 @@ items:
      release: {{ $.Release.Name }}
      heritage: {{ $.Release.Service }}
  spec:
  {{- if or $.Values.enableSelector (eq (default "extensions/v1beta1" $.Values.deploymentApiVersion) "apps/v1") }}
    selector:
      matchLabels:
        track: "{{ $.Values.application.track }}"
        tier: worker
        release: {{ $.Release.Name }}
  {{- end }}
    replicas: {{ $workerConfig.replicaCount }}
  {{- if $workerConfig.strategyType }}
    strategy:
+27 −123
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import (
)

const (
	chartName     = "auto-deploy-app-2.0.0-beta.3"
	chartName     = "auto-deploy-app-2.0.0-beta.4"
	helmChartPath = ".."
)

@@ -31,8 +31,7 @@ func TestDeploymentTemplate(t *testing.T) {

		ExpectedName         string
		ExpectedRelease      string
		ExpectedStrategyType extensions.DeploymentStrategyType
		ExpectedSelector     *metav1.LabelSelector
		ExpectedStrategyType appsV1.DeploymentStrategyType
	}{
		{
			CaseName: "happy",
@@ -42,7 +41,7 @@ func TestDeploymentTemplate(t *testing.T) {
			},
			ExpectedName:         "productionOverridden",
			ExpectedRelease:      "production",
			ExpectedStrategyType: extensions.DeploymentStrategyType(""),
			ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
		}, {
			// See https://github.com/helm/helm/issues/6006
			CaseName: "long release name",
@@ -58,25 +57,7 @@ func TestDeploymentTemplate(t *testing.T) {
			},
			ExpectedName:         "production",
			ExpectedRelease:      "production",
			ExpectedStrategyType: extensions.RecreateDeploymentStrategyType,
		},
		{
			CaseName: "enableSelector",
			Release:  "production",
			Values: map[string]string{
				"enableSelector": "true",
			},
			ExpectedName:         "production",
			ExpectedRelease:      "production",
			ExpectedStrategyType: extensions.DeploymentStrategyType(""),
			ExpectedSelector: &metav1.LabelSelector{
				MatchLabels: map[string]string{
					"app":     "production",
					"release": "production",
					"tier":    "web",
					"track":   "stable",
				},
			},
			ExpectedStrategyType: appsV1.RecreateDeploymentStrategyType,
		},
	} {
		t.Run(tc.CaseName, func(t *testing.T) {
@@ -105,7 +86,7 @@ func TestDeploymentTemplate(t *testing.T) {
				return
			}

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

			require.Equal(t, tc.ExpectedName, deployment.Name)
@@ -124,8 +105,6 @@ func TestDeploymentTemplate(t *testing.T) {
				"track":    "stable",
			}, deployment.Labels)

			require.Equal(t, tc.ExpectedSelector, deployment.Spec.Selector)

			require.Equal(t, map[string]string{
				"app.gitlab.com/app":           "auto-devops-examples/minimal-ruby-app",
				"app.gitlab.com/env":           "prod",
@@ -189,6 +168,7 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

	// Test Deployment selector
	for _, tc := range []struct {
		CaseName string
		Release  string
@@ -196,18 +176,13 @@ func TestDeploymentTemplate(t *testing.T) {

		ExpectedName     string
		ExpectedRelease  string
		ExpectedStrategyType appsV1.DeploymentStrategyType
		ExpectedSelector *metav1.LabelSelector
	}{
		{
			CaseName: "appsv1",
			CaseName:        "selector",
			Release:         "production",
			Values: map[string]string{
				"deploymentApiVersion": "apps/v1",
			},
			ExpectedName:    "production",
			ExpectedRelease: "production",
			ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
			ExpectedSelector: &metav1.LabelSelector{
				MatchLabels: map[string]string{
					"app":     "production",
@@ -239,11 +214,6 @@ func TestDeploymentTemplate(t *testing.T) {
			helm.UnmarshalK8SYaml(t, output, &deployment)

			require.Equal(t, tc.ExpectedName, deployment.Name)
			require.Equal(t, tc.ExpectedStrategyType, deployment.Spec.Strategy.Type)
			require.Equal(t, map[string]string{
				"app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app",
				"app.gitlab.com/env": "prod",
			}, deployment.Annotations)
			require.Equal(t, map[string]string{
				"app":      tc.ExpectedName,
				"chart":    chartName,
@@ -255,11 +225,6 @@ func TestDeploymentTemplate(t *testing.T) {

			require.Equal(t, tc.ExpectedSelector, deployment.Spec.Selector)

			require.Equal(t, map[string]string{
				"app.gitlab.com/app":           "auto-devops-examples/minimal-ruby-app",
				"app.gitlab.com/env":           "prod",
				"checksum/application-secrets": "",
			}, deployment.Spec.Template.Annotations)
			require.Equal(t, map[string]string{
				"app":     tc.ExpectedName,
				"release": tc.ExpectedRelease,
@@ -298,12 +263,12 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
				{
					ExpectedName:         "productionOverridden-worker1",
					ExpectedCmd:          []string{"echo", "worker1"},
					ExpectedStrategyType: extensions.DeploymentStrategyType(""),
					ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
				},
				{
					ExpectedName:         "productionOverridden-worker2",
					ExpectedCmd:          []string{"echo", "worker2"},
					ExpectedStrategyType: extensions.DeploymentStrategyType(""),
					ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
				},
			},
		}, {
@@ -327,46 +292,7 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
				{
					ExpectedName:         "production" + "-worker1",
					ExpectedCmd:          []string{"echo", "worker1"},
					ExpectedStrategyType: extensions.RecreateDeploymentStrategyType,
				},
			},
		},
		{
			CaseName: "enableSelector",
			Release:  "production",
			Values: map[string]string{
				"enableSelector":             "true",
				"workers.worker1.command[0]": "echo",
				"workers.worker1.command[1]": "worker1",
				"workers.worker2.command[0]": "echo",
				"workers.worker2.command[1]": "worker2",
			},
			ExpectedName:    "production",
			ExpectedRelease: "production",
			ExpectedDeployments: []workerDeploymentTestCase{
				{
					ExpectedName:         "production-worker1",
					ExpectedCmd:          []string{"echo", "worker1"},
					ExpectedStrategyType: extensions.DeploymentStrategyType(""),
					ExpectedSelector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"release": "production",
							"tier":    "worker",
							"track":   "stable",
						},
					},
				},
				{
					ExpectedName:         "production-worker2",
					ExpectedCmd:          []string{"echo", "worker2"},
					ExpectedStrategyType: extensions.DeploymentStrategyType(""),
					ExpectedSelector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"release": "production",
							"tier":    "worker",
							"track":   "stable",
						},
					},
					ExpectedStrategyType: appsV1.RecreateDeploymentStrategyType,
				},
			},
		},
@@ -419,8 +345,6 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
					"track":    "stable",
				}, deployment.Labels)

				require.Equal(t, expectedDeployment.ExpectedSelector, deployment.Spec.Selector)

				require.Equal(t, map[string]string{
					"app.gitlab.com/app":           "auto-devops-examples/minimal-ruby-app",
					"app.gitlab.com/env":           "prod",
@@ -438,6 +362,7 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
		})
	}

	// Tests worker selector
	for _, tc := range []struct {
		CaseName string
		Release  string
@@ -445,13 +370,12 @@ func TestWorkerDeploymentTemplate(t *testing.T) {

		ExpectedName        string
		ExpectedRelease     string
		ExpectedDeployments []workerDeploymentAppsV1TestCase
		ExpectedDeployments []workerDeploymentSelectorTestCase
	}{
		{
			CaseName: "appsv1",
			CaseName: "worker selector",
			Release:  "production",
			Values: map[string]string{
				"deploymentApiVersion":       "apps/v1",
				"workers.worker1.command[0]": "echo",
				"workers.worker1.command[1]": "worker1",
				"workers.worker2.command[0]": "echo",
@@ -459,11 +383,9 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
			},
			ExpectedName:    "production",
			ExpectedRelease: "production",
			ExpectedDeployments: []workerDeploymentAppsV1TestCase{
			ExpectedDeployments: []workerDeploymentSelectorTestCase{
				{
					ExpectedName: "production-worker1",
					ExpectedCmd:          []string{"echo", "worker1"},
					ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
					ExpectedSelector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"release": "production",
@@ -474,8 +396,6 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
				},
				{
					ExpectedName: "production-worker2",
					ExpectedCmd:          []string{"echo", "worker2"},
					ExpectedStrategyType: appsV1.DeploymentStrategyType(""),
					ExpectedSelector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"release": "production",
@@ -512,12 +432,7 @@ func TestWorkerDeploymentTemplate(t *testing.T) {
				deployment := deployments.Items[i]

				require.Equal(t, expectedDeployment.ExpectedName, deployment.Name)
				require.Equal(t, expectedDeployment.ExpectedStrategyType, deployment.Spec.Strategy.Type)

				require.Equal(t, map[string]string{
					"app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app",
					"app.gitlab.com/env": "prod",
				}, deployment.Annotations)
				require.Equal(t, map[string]string{
					"chart":    chartName,
					"heritage": "Helm",
@@ -528,19 +443,11 @@ func TestWorkerDeploymentTemplate(t *testing.T) {

				require.Equal(t, expectedDeployment.ExpectedSelector, deployment.Spec.Selector)

				require.Equal(t, map[string]string{
					"app.gitlab.com/app":           "auto-devops-examples/minimal-ruby-app",
					"app.gitlab.com/env":           "prod",
					"checksum/application-secrets": "",
				}, deployment.Spec.Template.Annotations)
				require.Equal(t, map[string]string{
					"release": tc.ExpectedRelease,
					"tier":    "worker",
					"track":   "stable",
				}, deployment.Spec.Template.Labels)

				require.Len(t, deployment.Spec.Template.Spec.Containers, 1)
				require.Equal(t, expectedDeployment.ExpectedCmd, deployment.Spec.Template.Spec.Containers[0].Command)
			}
		})
	}
@@ -963,21 +870,18 @@ func renderTemplate(t *testing.T, values map[string]string, releaseName string,
type workerDeploymentTestCase struct {
	ExpectedName         string
	ExpectedCmd          []string
	ExpectedStrategyType extensions.DeploymentStrategyType
	ExpectedSelector     *metav1.LabelSelector
	ExpectedStrategyType appsV1.DeploymentStrategyType
}

type workerDeploymentAppsV1TestCase struct {
type workerDeploymentSelectorTestCase struct {
	ExpectedName     string
	ExpectedCmd          []string
	ExpectedStrategyType appsV1.DeploymentStrategyType
	ExpectedSelector *metav1.LabelSelector
}

type deploymentList struct {
	metav1.TypeMeta `json:",inline"`

	Items []extensions.Deployment `json:"items" protobuf:"bytes,2,rep,name=items"`
	Items []appsV1.Deployment `json:"items" protobuf:"bytes,2,rep,name=items"`
}

type deploymentAppsV1List struct {
Loading