Loading assets/auto-deploy-app/templates/_helpers.tpl +1 −1 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version| replace "+" "_" }}" app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Values.extraLabels }} {{- toYaml $.Values.extraLabels }} {{ toYaml $.Values.extraLabels }} {{- end }} {{- end -}} Loading assets/auto-deploy-app/test/templates/cronjob_test.go +23 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ func TestCronjobMeta(t *testing.T) { ExpectedName string ExpectedRelease string ExpectedLabels map[string]string }{ { CaseName: "default", Loading @@ -34,6 +35,23 @@ func TestCronjobMeta(t *testing.T) { }, ExpectedName: "production", ExpectedRelease: "production", ExpectedLabels: nil, }, { CaseName: "extraLabels", 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", "extraLabels.firstLabel": "expected-label", }, ExpectedName: "production", ExpectedRelease: "production", ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, }, { CaseName: "overriden release", Loading @@ -47,6 +65,7 @@ func TestCronjobMeta(t *testing.T) { }, ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedLabels: nil, }, } { t.Run(tc.CaseName, func(t *testing.T) { Loading Loading @@ -81,7 +100,7 @@ func TestCronjobMeta(t *testing.T) { "app.gitlab.com/env": "prod", }, cronjob.Annotations) require.Equal(t, map[string]string{ ExpectedLabels := map[string]string{ "app": tc.ExpectedName, "chart": chartName, "heritage": "Helm", Loading @@ -92,7 +111,9 @@ func TestCronjobMeta(t *testing.T) { "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, cronjob.Labels) } mergeStringMap(ExpectedLabels, tc.ExpectedLabels) require.Equal(t, ExpectedLabels, cronjob.Labels) require.Equal(t, map[string]string{ "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", Loading assets/auto-deploy-app/test/templates/db_initialize_job_test.go +76 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,79 @@ func TestInitializeDatabaseImagePullSecrets(t *testing.T) { }) } } func TestInitializeDatabaseLabels(t *testing.T) { releaseName := "initialize-application-database-labels" for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedLabels map[string]string Template string }{ { CaseName: "no label", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", }, ExpectedLabels: nil, Template: "templates/db-initialize-job.yaml", }, { CaseName: "one label", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", "extraLabels.firstLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, Template: "templates/db-initialize-job.yaml", }, { CaseName: "multiple labels", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", "extraLabels.firstLabel": "expected-label", "extraLabels.secondLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", "secondLabel": "expected-label", }, Template: "templates/db-initialize-job.yaml", }, } { 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, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{tc.Template}) if err != nil { t.Error(err) return } deployment := new(appsV1.Deployment) helm.UnmarshalK8SYaml(t, output, &deployment) for key, value := range tc.ExpectedLabels { require.Equal(t, deployment.ObjectMeta.Labels[key], value) require.Equal(t, deployment.Spec.Template.ObjectMeta.Labels[key], value) } }) } } assets/auto-deploy-app/test/templates/db_migrate_hook_test.go +76 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,79 @@ func TestMigrateDatabaseImagePullSecrets(t *testing.T) { }) } } func TestMigrateDatabaseLabels(t *testing.T) { releaseName := "migrate-application-database-labels" for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedLabels map[string]string Template string }{ { CaseName: "no label", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", }, ExpectedLabels: nil, Template: "templates/db-migrate-hook.yaml", }, { CaseName: "one label", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", "extraLabels.firstLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, Template: "templates/db-migrate-hook.yaml", }, { CaseName: "multiple labels", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", "extraLabels.firstLabel": "expected-label", "extraLabels.secondLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", "secondLabel": "expected-label", }, Template: "templates/db-migrate-hook.yaml", }, } { 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, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{tc.Template}) if err != nil { t.Error(err) return } deployment := new(appsV1.Deployment) helm.UnmarshalK8SYaml(t, output, &deployment) for key, value := range tc.ExpectedLabels { require.Equal(t, deployment.ObjectMeta.Labels[key], value) require.Equal(t, deployment.Spec.Template.ObjectMeta.Labels[key], value) } }) } } assets/auto-deploy-app/test/templates/deployment_test.go +27 −15 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ func TestDeploymentTemplate(t *testing.T) { CaseName string Release string Values map[string]string ExpectedLabels map[string]string ExpectedErrorRegexp *regexp.Regexp Loading @@ -37,12 +38,29 @@ func TestDeploymentTemplate(t *testing.T) { ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedStrategyType: appsV1.DeploymentStrategyType(""), }, { ExpectedLabels: nil, }, { CaseName: "extraLabel", Release: "production", Values: map[string]string{ "releaseOverride": "productionOverridden", "extraLabels.firstLabel": "expected-label", }, ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedStrategyType: appsV1.DeploymentStrategyType(""), ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, }, { // See https://github.com/helm/helm/issues/6006 CaseName: "long release name", Release: strings.Repeat("r", 80), ExpectedErrorRegexp: regexp.MustCompile("Error: release name .* length must not be longer than 53"), ExpectedLabels: nil, }, { CaseName: "strategyType", Loading @@ -53,6 +71,7 @@ func TestDeploymentTemplate(t *testing.T) { ExpectedName: "production", ExpectedRelease: "production", ExpectedStrategyType: appsV1.RecreateDeploymentStrategyType, ExpectedLabels: nil, }, } { t.Run(tc.CaseName, func(t *testing.T) { Loading Loading @@ -91,7 +110,8 @@ func TestDeploymentTemplate(t *testing.T) { "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, deployment.Annotations) require.Equal(t, map[string]string{ ExpectedLabels := map[string]string{ "app": tc.ExpectedName, "chart": chartName, "heritage": "Helm", Loading @@ -102,25 +122,17 @@ func TestDeploymentTemplate(t *testing.T) { "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, deployment.Labels) } mergeStringMap(ExpectedLabels, tc.ExpectedLabels) require.Equal(t, ExpectedLabels, deployment.Labels) 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, "chart": chartName, "heritage": "Helm", "release": tc.ExpectedRelease, "tier": "web", "track": "stable", "app.kubernetes.io/name": tc.ExpectedName, "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, deployment.Spec.Template.Labels) require.Equal(t, ExpectedLabels, deployment.Spec.Template.Labels) }) } Loading Loading
assets/auto-deploy-app/templates/_helpers.tpl +1 −1 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version| replace "+" "_" }}" app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Values.extraLabels }} {{- toYaml $.Values.extraLabels }} {{ toYaml $.Values.extraLabels }} {{- end }} {{- end -}} Loading
assets/auto-deploy-app/test/templates/cronjob_test.go +23 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ func TestCronjobMeta(t *testing.T) { ExpectedName string ExpectedRelease string ExpectedLabels map[string]string }{ { CaseName: "default", Loading @@ -34,6 +35,23 @@ func TestCronjobMeta(t *testing.T) { }, ExpectedName: "production", ExpectedRelease: "production", ExpectedLabels: nil, }, { CaseName: "extraLabels", 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", "extraLabels.firstLabel": "expected-label", }, ExpectedName: "production", ExpectedRelease: "production", ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, }, { CaseName: "overriden release", Loading @@ -47,6 +65,7 @@ func TestCronjobMeta(t *testing.T) { }, ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedLabels: nil, }, } { t.Run(tc.CaseName, func(t *testing.T) { Loading Loading @@ -81,7 +100,7 @@ func TestCronjobMeta(t *testing.T) { "app.gitlab.com/env": "prod", }, cronjob.Annotations) require.Equal(t, map[string]string{ ExpectedLabels := map[string]string{ "app": tc.ExpectedName, "chart": chartName, "heritage": "Helm", Loading @@ -92,7 +111,9 @@ func TestCronjobMeta(t *testing.T) { "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, cronjob.Labels) } mergeStringMap(ExpectedLabels, tc.ExpectedLabels) require.Equal(t, ExpectedLabels, cronjob.Labels) require.Equal(t, map[string]string{ "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", Loading
assets/auto-deploy-app/test/templates/db_initialize_job_test.go +76 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,79 @@ func TestInitializeDatabaseImagePullSecrets(t *testing.T) { }) } } func TestInitializeDatabaseLabels(t *testing.T) { releaseName := "initialize-application-database-labels" for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedLabels map[string]string Template string }{ { CaseName: "no label", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", }, ExpectedLabels: nil, Template: "templates/db-initialize-job.yaml", }, { CaseName: "one label", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", "extraLabels.firstLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, Template: "templates/db-initialize-job.yaml", }, { CaseName: "multiple labels", Release: "production", Values: map[string]string{ "application.initializeCommand": "echo initialize", "extraLabels.firstLabel": "expected-label", "extraLabels.secondLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", "secondLabel": "expected-label", }, Template: "templates/db-initialize-job.yaml", }, } { 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, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{tc.Template}) if err != nil { t.Error(err) return } deployment := new(appsV1.Deployment) helm.UnmarshalK8SYaml(t, output, &deployment) for key, value := range tc.ExpectedLabels { require.Equal(t, deployment.ObjectMeta.Labels[key], value) require.Equal(t, deployment.Spec.Template.ObjectMeta.Labels[key], value) } }) } }
assets/auto-deploy-app/test/templates/db_migrate_hook_test.go +76 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,79 @@ func TestMigrateDatabaseImagePullSecrets(t *testing.T) { }) } } func TestMigrateDatabaseLabels(t *testing.T) { releaseName := "migrate-application-database-labels" for _, tc := range []struct { CaseName string Values map[string]string Release string ExpectedLabels map[string]string Template string }{ { CaseName: "no label", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", }, ExpectedLabels: nil, Template: "templates/db-migrate-hook.yaml", }, { CaseName: "one label", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", "extraLabels.firstLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, Template: "templates/db-migrate-hook.yaml", }, { CaseName: "multiple labels", Release: "production", Values: map[string]string{ "application.migrateCommand": "echo migrate", "extraLabels.firstLabel": "expected-label", "extraLabels.secondLabel": "expected-label", }, ExpectedLabels: map[string]string{ "firstLabel": "expected-label", "secondLabel": "expected-label", }, Template: "templates/db-migrate-hook.yaml", }, } { 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, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{tc.Template}) if err != nil { t.Error(err) return } deployment := new(appsV1.Deployment) helm.UnmarshalK8SYaml(t, output, &deployment) for key, value := range tc.ExpectedLabels { require.Equal(t, deployment.ObjectMeta.Labels[key], value) require.Equal(t, deployment.Spec.Template.ObjectMeta.Labels[key], value) } }) } }
assets/auto-deploy-app/test/templates/deployment_test.go +27 −15 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ func TestDeploymentTemplate(t *testing.T) { CaseName string Release string Values map[string]string ExpectedLabels map[string]string ExpectedErrorRegexp *regexp.Regexp Loading @@ -37,12 +38,29 @@ func TestDeploymentTemplate(t *testing.T) { ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedStrategyType: appsV1.DeploymentStrategyType(""), }, { ExpectedLabels: nil, }, { CaseName: "extraLabel", Release: "production", Values: map[string]string{ "releaseOverride": "productionOverridden", "extraLabels.firstLabel": "expected-label", }, ExpectedName: "productionOverridden", ExpectedRelease: "production", ExpectedStrategyType: appsV1.DeploymentStrategyType(""), ExpectedLabels: map[string]string{ "firstLabel": "expected-label", }, }, { // See https://github.com/helm/helm/issues/6006 CaseName: "long release name", Release: strings.Repeat("r", 80), ExpectedErrorRegexp: regexp.MustCompile("Error: release name .* length must not be longer than 53"), ExpectedLabels: nil, }, { CaseName: "strategyType", Loading @@ -53,6 +71,7 @@ func TestDeploymentTemplate(t *testing.T) { ExpectedName: "production", ExpectedRelease: "production", ExpectedStrategyType: appsV1.RecreateDeploymentStrategyType, ExpectedLabels: nil, }, } { t.Run(tc.CaseName, func(t *testing.T) { Loading Loading @@ -91,7 +110,8 @@ func TestDeploymentTemplate(t *testing.T) { "app.gitlab.com/app": "auto-devops-examples/minimal-ruby-app", "app.gitlab.com/env": "prod", }, deployment.Annotations) require.Equal(t, map[string]string{ ExpectedLabels := map[string]string{ "app": tc.ExpectedName, "chart": chartName, "heritage": "Helm", Loading @@ -102,25 +122,17 @@ func TestDeploymentTemplate(t *testing.T) { "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, deployment.Labels) } mergeStringMap(ExpectedLabels, tc.ExpectedLabels) require.Equal(t, ExpectedLabels, deployment.Labels) 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, "chart": chartName, "heritage": "Helm", "release": tc.ExpectedRelease, "tier": "web", "track": "stable", "app.kubernetes.io/name": tc.ExpectedName, "helm.sh/chart": chartName, "app.kubernetes.io/managed-by": "Helm", "app.kubernetes.io/instance": tc.ExpectedRelease, }, deployment.Spec.Template.Labels) require.Equal(t, ExpectedLabels, deployment.Spec.Template.Labels) }) } Loading