diff --git a/assets/auto-deploy-app/templates/cronjob.yaml b/assets/auto-deploy-app/templates/cronjob.yaml index 90a5b28cb00731862a84b8cc441b9e057fe1ebd6..9c09a81893143e962f5ec4bfe7f2a9a4934ae138 100644 --- a/assets/auto-deploy-app/templates/cronjob.yaml +++ b/assets/auto-deploy-app/templates/cronjob.yaml @@ -12,12 +12,16 @@ items: metadata: name: "{{ template "trackableappname" $ }}-{{ $jobName}}" annotations: - {{ 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.gitlab.app }} + app.gitlab.com/app: {{ $.Values.gitlab.app | quote }} + {{- end }} + {{- if $.Values.gitlab.env }} + app.gitlab.com/env: {{ $.Values.gitlab.env | quote }} + {{- end }} labels: track: "{{ $.Values.application.track }}" tier: "{{ $.Values.application.tier }}" - {{ include "sharedlabels" $ | nindent 6 }} + {{- include "sharedlabels" $ | nindent 6 }} spec: concurrencyPolicy: {{ default "Forbid" $jobConfig.concurrencyPolicy }} failedJobsHistoryLimit: {{ default 1 $jobConfig.failedJobsHistoryLimit }} @@ -36,8 +40,12 @@ items: metadata: annotations: checksum/application-secrets: "{{ $.Values.application.secretChecksum }}" - {{ 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.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 14 }} {{- end }} diff --git a/assets/auto-deploy-app/test/templates/cronjob_test.go b/assets/auto-deploy-app/test/templates/cronjob_test.go index d0aaa773bf84e4978d881545b350bc9032e82341..8b96e820680fae845610d85f1227d4a146cd3b81 100644 --- a/assets/auto-deploy-app/test/templates/cronjob_test.go +++ b/assets/auto-deploy-app/test/templates/cronjob_test.go @@ -161,14 +161,7 @@ func TestCronjobSchedule(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -226,14 +219,7 @@ func TestCronjobImage(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -368,14 +354,7 @@ func TestCronjobLivenessAndReadiness(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -436,14 +415,7 @@ func TestCronjobNodeSelector(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -527,14 +499,7 @@ func TestCronjobTolerations(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -607,12 +572,7 @@ func TestCronjobResources(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -626,7 +586,6 @@ func TestCronjobResources(t *testing.T) { func TestCronjobTemplateWithVolumeMounts(t *testing.T) { releaseName := "cronjob-with-volume-mounts-test" - templates := []string{"templates/cronjob.yaml"} hostPathDirectoryType := coreV1.HostPathDirectory configMapOptional := false @@ -697,18 +656,11 @@ func TestCronjobTemplateWithVolumeMounts(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - opts := &helm.Options{ + options := &helm.Options{ ValuesFiles: tc.valueFiles, SetValues: tc.values, } - output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -817,14 +769,7 @@ func TestCronjobAffinity(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -838,7 +783,6 @@ func TestCronjobAffinity(t *testing.T) { func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) { releaseName := "cronjob-with-extra-envfrom-test" - templates := []string{"templates/cronjob.yaml"} tcs := []struct { name string @@ -892,17 +836,10 @@ func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - opts := &helm.Options{ + options := &helm.Options{ SetValues: tc.values, } - output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates) - - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -915,7 +852,6 @@ func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) { func TestCronJobTemplateWithSecurityContext(t *testing.T) { releaseName := "cronjob-with-security-context" - templates := []string{"templates/cronjob.yaml"} tcs := []struct { name string @@ -933,17 +869,11 @@ func TestCronJobTemplateWithSecurityContext(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - opts := &helm.Options{ + options := &helm.Options{ SetValues: tc.values, } - output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates) - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -956,7 +886,6 @@ func TestCronJobTemplateWithSecurityContext(t *testing.T) { func TestCronJobTemplateWithContainerSecurityContext(t *testing.T) { releaseName := "cronjob-with-container-security-context" - templates := []string{"templates/cronjob.yaml"} tcs := []struct { name string @@ -976,17 +905,11 @@ func TestCronJobTemplateWithContainerSecurityContext(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - opts := &helm.Options{ + options := &helm.Options{ SetValues: tc.values, } - output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates) - if err != nil { - t.Error(err) - return - } - - require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output") + output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -1088,12 +1011,7 @@ func TestCronjobImagePullSecrets(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs) @@ -1183,12 +1101,7 @@ func TestCronjobPodAnnotations(t *testing.T) { KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), } - output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"}) - - if err != nil { - t.Error(err) - return - } + output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil) var cronjobs batchV1beta1.CronJobList helm.UnmarshalK8SYaml(t, output, &cronjobs)