From 68c400618b7968a762c8e1846798b0f97997d464 Mon Sep 17 00:00:00 2001 From: Reinhard Naegele Date: Fri, 14 Feb 2020 15:03:43 +0100 Subject: [PATCH 1/4] Don't create provided namespace Adding support for Helm 3 introduced creating namespaces because Helm does not do this automatically anymore. However, a regression was introduced that always creates namespaces, even if a dedicated namespace is provided via CLI flag. Signed-off-by: Reinhard Naegele --- pkg/chart/chart.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index ef122b02..a8353542 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -16,11 +16,12 @@ package chart import ( "fmt" - "github.com/Masterminds/semver" "io/ioutil" "path/filepath" "strings" + "github.com/Masterminds/semver" + "github.com/helm/chart-testing/v3/pkg/config" "github.com/helm/chart-testing/v3/pkg/exec" "github.com/helm/chart-testing/v3/pkg/tool" @@ -541,8 +542,10 @@ func (t *Testing) doInstall(chart *Chart) error { namespace, release, releaseSelector, cleanup := t.generateInstallConfig(chart) defer cleanup() - if err := t.kubectl.CreateNamespace(namespace); err != nil { - return err + if t.config.Namespace == "" { + if err := t.kubectl.CreateNamespace(namespace); err != nil { + return err + } } if err := t.helm.InstallWithValues(chart.Path(), valuesFile, namespace, release); err != nil { return err @@ -579,8 +582,10 @@ func (t *Testing) doUpgrade(oldChart, newChart *Chart, oldChartMustPass bool) er namespace, release, releaseSelector, cleanup := t.generateInstallConfig(oldChart) defer cleanup() - if err := t.kubectl.CreateNamespace(namespace); err != nil { - return err + if t.config.Namespace == "" { + if err := t.kubectl.CreateNamespace(namespace); err != nil { + return err + } } // Install previous version of chart. If installation fails, ignore this release. if err := t.helm.InstallWithValues(oldChart.Path(), valuesFile, namespace, release); err != nil { From 13fab9d2c31365394db0262da98d1f1311da4b7c Mon Sep 17 00:00:00 2001 From: Reinhard Naegele Date: Fri, 14 Feb 2020 15:52:40 +0100 Subject: [PATCH 2/4] Fix statefulset test Signed-off-by: Reinhard Naegele --- .../test_charts/mutating-sfs-volumeclaim/templates/service.yaml | 1 + .../mutating-sfs-volumeclaim/templates/statefulset.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/service.yaml b/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/service.yaml index 9866f352..f5620693 100644 --- a/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/service.yaml +++ b/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/service.yaml @@ -9,6 +9,7 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} spec: type: {{ .Values.service.type }} + clusterIP: None ports: - port: {{ .Values.service.port }} targetPort: http diff --git a/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/statefulset.yaml b/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/statefulset.yaml index c412858e..323caf87 100644 --- a/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/statefulset.yaml +++ b/pkg/chart/test_charts/mutating-sfs-volumeclaim/templates/statefulset.yaml @@ -9,6 +9,7 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} spec: replicas: {{ .Values.replicaCount }} + serviceName: {{ include "nginx.fullname" . }} selector: matchLabels: app.kubernetes.io/name: {{ include "nginx.name" . }} From bc184801642156b238fc248db43f72c4844c2edc Mon Sep 17 00:00:00 2001 From: Reinhard Naegele Date: Fri, 14 Feb 2020 16:03:54 +0100 Subject: [PATCH 3/4] Fix deployment apiVersion Signed-off-by: Reinhard Naegele --- .../mutating-deployment-selector/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/chart/test_charts/mutating-deployment-selector/templates/deployment.yaml b/pkg/chart/test_charts/mutating-deployment-selector/templates/deployment.yaml index 8a60425f..5f3f9345 100644 --- a/pkg/chart/test_charts/mutating-deployment-selector/templates/deployment.yaml +++ b/pkg/chart/test_charts/mutating-deployment-selector/templates/deployment.yaml @@ -1,4 +1,4 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "nginx.fullname" . }} From 6d0225c18e1bbc0de75b6e2af8e2aea0c299d9b1 Mon Sep 17 00:00:00 2001 From: Reinhard Naegele Date: Fri, 14 Feb 2020 16:15:47 +0100 Subject: [PATCH 4/4] Create custom namespace before test Signed-off-by: Reinhard Naegele --- pkg/chart/integration_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/chart/integration_test.go b/pkg/chart/integration_test.go index 46d05646..330a40ba 100644 --- a/pkg/chart/integration_test.go +++ b/pkg/chart/integration_test.go @@ -76,6 +76,11 @@ func TestInstallChart(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { ct := newTestingHelmIntegration(tc.cfg) + namespace := tc.cfg.Namespace + if namespace != "" { + ct.kubectl.CreateNamespace(namespace) + defer ct.kubectl.DeleteNamespace(namespace) + } result := ct.InstallChart(mustNewChart(tc.chartDir)) if result.Error != tc.output.Error {