Skip to content

Commit

Permalink
Don't create provided namespace (#205)
Browse files Browse the repository at this point in the history
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 <[email protected]>

* Fix statefulset test

Signed-off-by: Reinhard Naegele <[email protected]>

* Fix deployment apiVersion

Signed-off-by: Reinhard Naegele <[email protected]>

* Create custom namespace before test

Signed-off-by: Reinhard Naegele <[email protected]>
  • Loading branch information
unguiculus authored Feb 27, 2020
1 parent aacb8f4 commit f5f1e77
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/chart/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nginx.fullname" . }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down

0 comments on commit f5f1e77

Please sign in to comment.