From 0156ca61ca6999bcfb093d210a4ee597aece0edf Mon Sep 17 00:00:00 2001 From: Thomas Dy Date: Fri, 27 Nov 2020 16:28:26 +0900 Subject: [PATCH] Fix capabilities changes leaking into other tests Signed-off-by: Thomas Dy --- .../output/template-show-only-multiple.txt | 1 - .../output/template-show-only-one.txt | 1 - .../testdata/output/template-skip-tests.txt | 1 - .../testdata/output/template-with-crds.txt | 1 - .../output/template-with-kube-version.txt | 32 ++++++++++++++++++- pkg/action/install.go | 2 +- pkg/chartutil/capabilities.go | 8 +++++ 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/cmd/helm/testdata/output/template-show-only-multiple.txt b/cmd/helm/testdata/output/template-show-only-multiple.txt index 20b6bebed..81a1d8e3c 100644 --- a/cmd/helm/testdata/output/template-show-only-multiple.txt +++ b/cmd/helm/testdata/output/template-show-only-multiple.txt @@ -10,7 +10,6 @@ metadata: kube-version/major: "1" kube-version/minor: "20" kube-version/version: "v1.20.0" - kube-api-version/test: v1 spec: type: ClusterIP ports: diff --git a/cmd/helm/testdata/output/template-show-only-one.txt b/cmd/helm/testdata/output/template-show-only-one.txt index f3aedb55d..a354bc0cc 100644 --- a/cmd/helm/testdata/output/template-show-only-one.txt +++ b/cmd/helm/testdata/output/template-show-only-one.txt @@ -10,7 +10,6 @@ metadata: kube-version/major: "1" kube-version/minor: "20" kube-version/version: "v1.20.0" - kube-api-version/test: v1 spec: type: ClusterIP ports: diff --git a/cmd/helm/testdata/output/template-skip-tests.txt b/cmd/helm/testdata/output/template-skip-tests.txt index 6e657e50b..8e8181474 100644 --- a/cmd/helm/testdata/output/template-skip-tests.txt +++ b/cmd/helm/testdata/output/template-skip-tests.txt @@ -74,7 +74,6 @@ metadata: kube-version/major: "1" kube-version/minor: "20" kube-version/version: "v1.20.0" - kube-api-version/test: v1 spec: type: ClusterIP ports: diff --git a/cmd/helm/testdata/output/template-with-crds.txt b/cmd/helm/testdata/output/template-with-crds.txt index fe8e24520..758e2e39f 100644 --- a/cmd/helm/testdata/output/template-with-crds.txt +++ b/cmd/helm/testdata/output/template-with-crds.txt @@ -91,7 +91,6 @@ metadata: kube-version/major: "1" kube-version/minor: "20" kube-version/version: "v1.20.0" - kube-api-version/test: v1 spec: type: ClusterIP ports: diff --git a/cmd/helm/testdata/output/template-with-kube-version.txt b/cmd/helm/testdata/output/template-with-kube-version.txt index 84397a15a..836905268 100644 --- a/cmd/helm/testdata/output/template-with-kube-version.txt +++ b/cmd/helm/testdata/output/template-with-kube-version.txt @@ -11,7 +11,8 @@ kind: Role metadata: name: subchart-role rules: -- resources: ["*"] +- apiGroups: [""] + resources: ["pods"] verbs: ["get","list","watch"] --- # Source: subchart/templates/subdir/rolebinding.yaml @@ -82,3 +83,32 @@ spec: name: nginx selector: app.kubernetes.io/name: subchart +--- +# Source: subchart/templates/tests/test-config.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: "RELEASE-NAME-testconfig" + annotations: + "helm.sh/hook": test +data: + message: Hello World +--- +# Source: subchart/templates/tests/test-nothing.yaml +apiVersion: v1 +kind: Pod +metadata: + name: "RELEASE-NAME-test" + annotations: + "helm.sh/hook": test +spec: + containers: + - name: test + image: "alpine:latest" + envFrom: + - configMapRef: + name: "RELEASE-NAME-testconfig" + command: + - echo + - "$message" + restartPolicy: Never diff --git a/pkg/action/install.go b/pkg/action/install.go index 6fdd672b9..af99717d1 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -198,7 +198,7 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release. if i.ClientOnly { // Add mock objects in here so it doesn't use Kube API server // NOTE(bacongobbler): used for `helm template` - i.cfg.Capabilities = chartutil.DefaultCapabilities + i.cfg.Capabilities = chartutil.DefaultCapabilities.Copy() if i.KubeVersion != nil { i.cfg.Capabilities.KubeVersion = *i.KubeVersion } diff --git a/pkg/chartutil/capabilities.go b/pkg/chartutil/capabilities.go index 190744665..d24228056 100644 --- a/pkg/chartutil/capabilities.go +++ b/pkg/chartutil/capabilities.go @@ -59,6 +59,14 @@ type Capabilities struct { HelmVersion helmversion.BuildInfo } +func (capabilities *Capabilities) Copy() *Capabilities { + return &Capabilities{ + KubeVersion: capabilities.KubeVersion, + APIVersions: capabilities.APIVersions, + HelmVersion: capabilities.HelmVersion, + } +} + // KubeVersion is the Kubernetes version. type KubeVersion struct { Version string // Kubernetes version