diff --git a/assets/auto-deploy-app/Chart.yaml b/assets/auto-deploy-app/Chart.yaml index 1754009b31b1c8264d729ddf01d4158bc2729402..56c8cb5465f32f4c62372ee80a66589aab2b49d1 100644 --- a/assets/auto-deploy-app/Chart.yaml +++ b/assets/auto-deploy-app/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 description: GitLab's Auto-deploy Helm Chart name: auto-deploy-app -version: 2.40.1 +version: 2.64.0 icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png diff --git a/assets/auto-deploy-app/README.md b/assets/auto-deploy-app/README.md index de54503ec37e81577ff51ce8378119fd84fcd196..334f99ca0b8f53880b2eadd62aa8074d6ab50924 100644 --- a/assets/auto-deploy-app/README.md +++ b/assets/auto-deploy-app/README.md @@ -21,6 +21,7 @@ | 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 | `{}` | +| hostNetwork | Use the host's network namespace. | `false` | | dnsPolicy | Pod DNS policy | `{}` | | dnsConfig | [Pod DNS config](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-dns-config) | `{}` | | nodeSelector | Node labels for pod assignment | `{}` | diff --git a/assets/auto-deploy-app/templates/deployment.yaml b/assets/auto-deploy-app/templates/deployment.yaml index 5520a20e7c57c94f80f562673312c0dc45d41565..5424c1988a41f7a25a0a6628e0615789fda9fc5e 100644 --- a/assets/auto-deploy-app/templates/deployment.yaml +++ b/assets/auto-deploy-app/templates/deployment.yaml @@ -45,6 +45,9 @@ spec: nodeSelector: {{ toYaml .Values.nodeSelector | indent 8 }} {{- end }} +{{- if .Values.hostNetwork }} + hostNetwork: {{ .Values.hostNetwork }} +{{- end }} {{- if .Values.dnsPolicy }} dnsPolicy: {{ .Values.dnsPolicy }} {{- end }} @@ -195,7 +198,7 @@ spec: port: {{ .Values.readinessProbe.port | default .Values.service.internalPort }} {{- if .Values.readinessProbe.httpHeaders }} httpHeaders: -{{- range $httpHeader := .Values.readinessProbe.httpHeaders }} +{{- range $httpHeader := .Values.readinessProbe.httpHeaders }} - name: {{ $httpHeader.name }} value: {{ $httpHeader.value }} {{- end }} @@ -242,7 +245,7 @@ spec: {{ toYaml .Values.resources | indent 12 }} {{- if or (.Values.persistence.enabled) (.Values.extraVolumeMounts) }} volumeMounts: -{{- if .Values.persistence.enabled }} +{{- if .Values.persistence.enabled }} {{- range $volume := .Values.persistence.volumes }} - name: {{ $volume.name | quote }} mountPath: {{ $volume.mount.path | quote }} @@ -252,7 +255,7 @@ spec: {{- end }} {{- end }} {{- if .Values.extraVolumeMounts }} -{{ toYaml .Values.extraVolumeMounts | indent 10 }} +{{ toYaml .Values.extraVolumeMounts | indent 10 }} {{- end }} {{- end }} {{- end -}} diff --git a/assets/auto-deploy-app/templates/worker-deployment.yaml b/assets/auto-deploy-app/templates/worker-deployment.yaml index d04b34c29dd0c8cfe4acf769c7ee0a4551f66e49..e3c7ab8d962c1ce8f16b9da1c2ad5c3a399c5dc4 100644 --- a/assets/auto-deploy-app/templates/worker-deployment.yaml +++ b/assets/auto-deploy-app/templates/worker-deployment.yaml @@ -55,6 +55,11 @@ items: {{ toYaml $nodeSelectorConfig | indent 10 }} {{- end }} {{- end }} +{{- with $hostNetworkConfig := default $.Values.hostNetwork $workerConfig.hostNetwork -}} +{{- if $hostNetworkConfig }} + hostNetwork: {{ $hostNetworkConfig }} +{{- end }} +{{- end }} {{- with $dnsPolicyConfig := default $.Values.dnsPolicy $workerConfig.dnsPolicy -}} {{- if $dnsPolicyConfig }} dnsPolicy: {{ $dnsPolicyConfig }} @@ -191,7 +196,7 @@ items: {{ $workerConfig.resources | default $.Values.resources | toYaml | indent 12 }} {{- if $workerConfig.extraVolumeMounts }} volumeMounts: -{{ toYaml $workerConfig.extraVolumeMounts | indent 12 }} +{{ toYaml $workerConfig.extraVolumeMounts | indent 12 }} {{- end }} {{- end -}} {{- end -}} diff --git a/assets/auto-deploy-app/test/templates/deployment_test.go b/assets/auto-deploy-app/test/templates/deployment_test.go index 98c21254fd441a53ed73f10d77f2285119cb7097..63dfbf5001af2b68609a1e95b9b0855feea86a44 100644 --- a/assets/auto-deploy-app/test/templates/deployment_test.go +++ b/assets/auto-deploy-app/test/templates/deployment_test.go @@ -225,6 +225,45 @@ func TestDeploymentTemplate(t *testing.T) { }) } + for _, tc := range []struct { + CaseName string + Release string + Values map[string]string + ExpectedHostNetwork bool + }{ + { + CaseName: "root hostNetwork is defined", + Release: "production", + Values: map[string]string{ + "hostNetwork": "true", + }, + ExpectedHostNetwork: bool(true), + }, + } { + 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.ExpectedHostNetwork, deployment.Spec.Template.Spec.HostNetwork) + }) + } + // serviceAccountName for _, tc := range []struct { CaseName string diff --git a/assets/auto-deploy-app/test/templates/test_helpers.go b/assets/auto-deploy-app/test/templates/test_helpers.go index eea2e2c1e2a6c00d068f94be2b3e67d7b1e09e69..345692800b76360a5af709d51e2d34c7a41b96d8 100644 --- a/assets/auto-deploy-app/test/templates/test_helpers.go +++ b/assets/auto-deploy-app/test/templates/test_helpers.go @@ -92,6 +92,10 @@ type workerDeploymentServiceAccountTestCase struct { ExpectedServiceAccountName string } +type workerDeploymentHostNetworkTestCase struct { + ExpectedHostNetwork bool +} + type deploymentList struct { metav1.TypeMeta `json:",inline"` diff --git a/assets/auto-deploy-app/test/templates/workerdeployment_test.go b/assets/auto-deploy-app/test/templates/workerdeployment_test.go index 76bfa27b8f77635b0cf69d4a35b7b10a884e53ae..a4dca6a5f14346a86de9468b982fa7b20714c335 100644 --- a/assets/auto-deploy-app/test/templates/workerdeployment_test.go +++ b/assets/auto-deploy-app/test/templates/workerdeployment_test.go @@ -260,6 +260,79 @@ func TestWorkerDeploymentTemplate(t *testing.T) { }) } + for _, tc := range []struct { + CaseName string + Release string + Values map[string]string + + ExpectedDeployments []workerDeploymentHostNetworkTestCase + }{ + { + CaseName: "worker hostNetwork is defined", + Release: "production", + Values: map[string]string{ + "workers.worker1.hostNetwork": "true", + }, + ExpectedDeployments: []workerDeploymentHostNetworkTestCase{ + { + ExpectedHostNetwork: bool(true), + }, + }, + }, + { + CaseName: "root hostNetwork is defined", + Release: "production", + Values: map[string]string{ + "hostNetwork": "true", + }, + ExpectedDeployments: []workerDeploymentHostNetworkTestCase{ + { + ExpectedHostNetwork: bool(true), + }, + }, + }, + } { + 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", + "workers.worker1.command[0]": "echo", + "workers.worker1.command[1]": "worker1", + } + + mergeStringMap(values, tc.Values) + + options := &helm.Options{ + SetValues: values, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + output := helm.RenderTemplate( + t, + options, + helmChartPath, + tc.Release, + []string{"templates/worker-deployment.yaml"}, + ) + + var deployments deploymentAppsV1List + helm.UnmarshalK8SYaml(t, output, &deployments) + + require.Len(t, deployments.Items, len(tc.ExpectedDeployments)) + + for i, expectedDeployment := range tc.ExpectedDeployments { + deployment := deployments.Items[i] + require.Equal( + t, + expectedDeployment.ExpectedHostNetwork, + deployment.Spec.Template.Spec.HostNetwork, + ) + } + }) + } + // Tests worker selector for _, tc := range []struct { CaseName string diff --git a/assets/auto-deploy-app/values.yaml b/assets/auto-deploy-app/values.yaml index 7adfa151d0de7e6f7e1b08f0be8db3f183f9e640..4dc059b64836f9a952e30f27f11afc96c93139cc 100644 --- a/assets/auto-deploy-app/values.yaml +++ b/assets/auto-deploy-app/values.yaml @@ -18,6 +18,7 @@ lifecycle: {} # command: ["/bin/sh", "-c", "sleep 10"] podAnnotations: {} nodeSelector: {} +hostNetwork: false dnsPolicy: {} dnsConfig: {} # nameservers: