Commit 88e7d026 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason
Browse files

Merge branch 'deployment-hostAliases' into 'master'

Deployment host aliases

See merge request gitlab-org/cluster-integration/auto-deploy-image!261
parents 0fe2e3d3 70599c7d
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.24.0
version: 2.25.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
@@ -24,6 +24,7 @@
| nodeSelector                  | Node labels for pod assignment | `{}`           |
| tolerations                   | List of node taints to tolerate | `[]`          |
| terminationGracePeriodSeconds | The amount of time in seconds a pod is given to terminate | [See the Kubernetes API for reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle)          |
| hostAliases                   | If present, this will set static hosts to the pod configuration | [See the Kubernetes API for reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#hostname-and-name-resolution) |
| initContainers                | Containers that are run before the app containers are started. | `[]`          |
| topologySpreadConstraints     | [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/) | `[]`          |
| affinity                      | Node affinity for pod assignment | `{}`          |
+5 −1
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ spec:
{{- end }}
{{- end }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- if .Values.hostAliases }}
      hostAliases:
{{ toYaml .Values.hostAliases | indent 8 }}
{{- end }}
      containers:
      - name: {{ .Chart.Name }}
        image: {{ template "imagename" . }}
+4 −0
Original line number Diff line number Diff line
@@ -74,6 +74,10 @@ items:
{{- end }}
{{- end }}
        terminationGracePeriodSeconds: {{ $workerConfig.terminationGracePeriodSeconds }}
{{- if $workerConfig.hostAliases }}
        hostAliases:
{{ $workerConfig.hostAliases | indent 10 }}
{{- end }}
        containers:
        - name: {{ $.Chart.Name }}-{{ $workerName }}
          image: {{ template "imagename" $ }}
+60 −0
Original line number Diff line number Diff line
@@ -422,6 +422,66 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

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

		ExpectedHostAliases []coreV1.HostAlias
	}{
		{
			CaseName:            "default hostAliases",
			Release:             "production",
			ExpectedHostAliases: nil,
		},
		{
			CaseName: "hostAliases for two IP addresses",
			Release:  "production",
			Values: map[string]string{
				"hostAliases[0].ip":           "1.2.3.4",
				"hostAliases[0].hostnames[0]": "host1.example1.com",
				"hostAliases[1].ip":           "5.6.7.8",
				"hostAliases[1].hostnames[0]": "host1.example2.com",
				"hostAliases[1].hostnames[1]": "host2.example2.com",
			},

			ExpectedHostAliases: []coreV1.HostAlias{
				{
					IP:        "1.2.3.4",
					Hostnames: []string{"host1.example1.com"},
				},
				{
					IP:        "5.6.7.8",
					Hostnames: []string{"host1.example2.com", "host2.example2.com"},
				},
			},
		},
	} {
		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.ExpectedHostAliases, deployment.Spec.Template.Spec.HostAliases)
		})
	}

	// Test Deployment selector
	for _, tc := range []struct {
		CaseName string
Loading