Loading assets/auto-deploy-app/templates/cronjob.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ items: {{ if $.Values.gitlab.app }}app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}{{ end }} {{ if $.Values.gitlab.env }}app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}{{ end }} {{- if $.Values.podAnnotations }} {{- toYaml $.Values.podAnnotations | nindent 12 }} {{- toYaml $.Values.podAnnotations | nindent 14 }} {{- end }} labels: app: {{ template "appname" $ }} Loading assets/auto-deploy-app/test/templates/cronjob_test.go +95 −0 Original line number Diff line number Diff line Loading @@ -989,3 +989,98 @@ func TestCronjobImagePullSecrets(t *testing.T) { }) } } func TestCronjobPodAnnotations(t *testing.T) { for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", "podAnnotations.firstAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, }, } { 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{ ValuesFiles: []string{}, SetValues: values, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) if err != nil { t.Error(err) return } var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) for _, cronjob := range cronjobs.Items { require.Equal(t, tc.ExpectedPodAnnotations, cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Annotations) } }) } } No newline at end of file assets/auto-deploy-app/test/templates/deployment_test.go +70 −0 Original line number Diff line number Diff line Loading @@ -342,6 +342,76 @@ func TestDeploymentTemplate(t *testing.T) { }) } // podAnnotations for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{}, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, }, } { 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.ExpectedPodAnnotations, deployment.Spec.Template.ObjectMeta.Annotations) }) } // serviceAccountName for _, tc := range []struct { CaseName string Loading assets/auto-deploy-app/test/templates/workerdeployment_test.go +73 −0 Original line number Diff line number Diff line Loading @@ -419,6 +419,79 @@ func TestWorkerDeploymentTemplate(t *testing.T) { }) } // podAnnotations for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{ "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", }, }, } { t.Run(tc.CaseName, func(t *testing.T) { namespaceName := "minimal-ruby-app-" + strings.ToLower(random.UniqueId()) values := map[string]string{} 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 deploymentList t.Log("jopa") helm.UnmarshalK8SYaml(t, output, &deployments) for i := range deployments.Items { deployment := deployments.Items[i] require.Equal(t, tc.ExpectedPodAnnotations, deployment.Spec.Template.ObjectMeta.Annotations) } }) } for _, tc := range []struct { CaseName string Release string Loading Loading
assets/auto-deploy-app/templates/cronjob.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ items: {{ if $.Values.gitlab.app }}app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}{{ end }} {{ if $.Values.gitlab.env }}app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}{{ end }} {{- if $.Values.podAnnotations }} {{- toYaml $.Values.podAnnotations | nindent 12 }} {{- toYaml $.Values.podAnnotations | nindent 14 }} {{- end }} labels: app: {{ template "appname" $ }} Loading
assets/auto-deploy-app/test/templates/cronjob_test.go +95 −0 Original line number Diff line number Diff line Loading @@ -989,3 +989,98 @@ func TestCronjobImagePullSecrets(t *testing.T) { }) } } func TestCronjobPodAnnotations(t *testing.T) { for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", "podAnnotations.firstAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{ "cronjobs.job1.command[0]": "echo", "cronjobs.job1.args[0]": "hello", "cronjobs.job2.command[0]": "echo", "cronjobs.job2.args[0]": "hello", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, }, } { 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{ ValuesFiles: []string{}, SetValues: values, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) if err != nil { t.Error(err) return } var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) for _, cronjob := range cronjobs.Items { require.Equal(t, tc.ExpectedPodAnnotations, cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Annotations) } }) } } No newline at end of file
assets/auto-deploy-app/test/templates/deployment_test.go +70 −0 Original line number Diff line number Diff line Loading @@ -342,6 +342,76 @@ func TestDeploymentTemplate(t *testing.T) { }) } // podAnnotations for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{}, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, }, } { 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.ExpectedPodAnnotations, deployment.Spec.Template.ObjectMeta.Annotations) }) } // serviceAccountName for _, tc := range []struct { CaseName string Loading
assets/auto-deploy-app/test/templates/workerdeployment_test.go +73 −0 Original line number Diff line number Diff line Loading @@ -419,6 +419,79 @@ func TestWorkerDeploymentTemplate(t *testing.T) { }) } // podAnnotations for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedPodAnnotations map[string]string }{ { CaseName: "one podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "firstAnnotation": "expected-annotation", }, }, { CaseName: "multiple podAnnotations", Release: "production", Values: map[string]string{ "podAnnotations.firstAnnotation": "expected-annotation", "podAnnotations.secondAnnotation": "expected-annotation", "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", "firstAnnotation": "expected-annotation", "secondAnnotation": "expected-annotation", }, }, { CaseName: "no podAnnotations", Release: "production", Values: map[string]string{ "workers.worker1.command[0]": "echo", }, ExpectedPodAnnotations: map[string]string{ "checksum/application-secrets": "", }, }, } { t.Run(tc.CaseName, func(t *testing.T) { namespaceName := "minimal-ruby-app-" + strings.ToLower(random.UniqueId()) values := map[string]string{} 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 deploymentList t.Log("jopa") helm.UnmarshalK8SYaml(t, output, &deployments) for i := range deployments.Items { deployment := deployments.Items[i] require.Equal(t, tc.ExpectedPodAnnotations, deployment.Spec.Template.ObjectMeta.Annotations) } }) } for _, tc := range []struct { CaseName string Release string Loading