From 29fdb57addeaae2916f3ee8a104eab39ccc13640 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 27 May 2020 21:34:44 +0900 Subject: [PATCH] fix: Support for kustomization as chart A kustomization has not been properly chartified when a kustomization is specified on `releases[].chart` but there were no `releases[].strategicMergePatches` and `jsonPatches` specified. This fixes that. --- pkg/state/helmx.go | 9 ++++ test/advanced/helmfile.yaml | 49 +++++++++++++++++++++ test/advanced/kustomapp/all.yaml | 7 +++ test/advanced/kustomapp/kustomization.yaml | 2 + test/advanced/kustomapp2/all.yaml | 7 +++ test/advanced/kustomapp2/kustomization.yaml | 2 + 6 files changed, 76 insertions(+) create mode 100644 test/advanced/helmfile.yaml create mode 100644 test/advanced/kustomapp/all.yaml create mode 100644 test/advanced/kustomapp/kustomization.yaml create mode 100644 test/advanced/kustomapp2/all.yaml create mode 100644 test/advanced/kustomapp2/kustomization.yaml diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 9f1abb47..23989abf 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -3,6 +3,8 @@ package state import ( "github.com/roboll/helmfile/pkg/helmexec" "github.com/variantdev/chartify" + "os" + "path/filepath" "strings" ) @@ -29,6 +31,13 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp opts.ChartVersion = release.Version + dir := filepath.Join(st.basePath, release.Chart) + if stat, _ := os.Stat(dir); stat != nil && stat.IsDir() { + if exists, err := st.fileExists(filepath.Join(dir, "Chart.yaml")); err == nil && !exists { + shouldRun = true + } + } + for _, d := range release.Dependencies { var dep string diff --git a/test/advanced/helmfile.yaml b/test/advanced/helmfile.yaml new file mode 100644 index 00000000..8e71f155 --- /dev/null +++ b/test/advanced/helmfile.yaml @@ -0,0 +1,49 @@ +repositories: +- name: incubator + url: https://kubernetes-charts-incubator.storage.googleapis.com + +releases: +- name: kustomapp + chart: ./kustomapp + values: + - namePrefix: kustomapp- +- name: raw1 + chart: incubator/raw + values: + - resources: + - apiVersion: v1 + kind: ConfigMap + metadata: + name: raw1 + namespace: default + data: + foo: FOO + strategicMergePatches: + - apiVersion: v1 + kind: ConfigMap + metadata: + name: raw1 + namespace: default + data: + bar: BAR +- name: raw2 + chart: incubator/raw + values: + - resources: + - apiVersion: v1 + kind: ConfigMap + metadata: + name: raw2 + namespace: default + data: + foo: FOO + jsonPatches: + - target: + version: v1 + kind: ConfigMap + name: raw2 + namespace: default + patch: + - op: replace + path: /data/baz + value: "BAZ" diff --git a/test/advanced/kustomapp/all.yaml b/test/advanced/kustomapp/all.yaml new file mode 100644 index 00000000..abf347a3 --- /dev/null +++ b/test/advanced/kustomapp/all.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: kustomapp + namespace: default +data: + kustomappfoo: FOO diff --git a/test/advanced/kustomapp/kustomization.yaml b/test/advanced/kustomapp/kustomization.yaml new file mode 100644 index 00000000..0b0b2bcd --- /dev/null +++ b/test/advanced/kustomapp/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- all.yaml diff --git a/test/advanced/kustomapp2/all.yaml b/test/advanced/kustomapp2/all.yaml new file mode 100644 index 00000000..0e5bddd2 --- /dev/null +++ b/test/advanced/kustomapp2/all.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: kustomapp2 + namespace: default +data: + kustomappfoo: FOO diff --git a/test/advanced/kustomapp2/kustomization.yaml b/test/advanced/kustomapp2/kustomization.yaml new file mode 100644 index 00000000..0b0b2bcd --- /dev/null +++ b/test/advanced/kustomapp2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- all.yaml