From d34261218d8da0c60e3b7ad6192e2d620f70cdb7 Mon Sep 17 00:00:00 2001 From: arttii Date: Wed, 13 Jan 2021 11:52:02 +0100 Subject: [PATCH] add namespace to state vals for app --- cmd/apply.go | 8 ++++---- pkg/template/helmfile.go | 4 ++-- realm/namespaces/_defaults.yaml | 4 ++-- realm/namespaces/default/monitoring/dummy.yaml | 4 +++- realm/namespaces/default/monitoring/test.yaml | 5 ++++- realm/namespaces/default/testing/test1.yaml | 4 +++- realm/values/env/dev/default/values.yaml | 4 ++++ 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 realm/values/env/dev/default/values.yaml diff --git a/cmd/apply.go b/cmd/apply.go index 3dcdb3f..e47f248 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -25,7 +25,7 @@ import ( "github.com/spf13/cobra" ) -func templateApp(app string, inputFilePath string, appGroupDir string, lint bool) error { +func templateApp(app string, namespace string, inputFilePath string, appGroupDir string, lint bool) error { targeAppDir := utils.ConcatDirs(appGroupDir, app) @@ -39,7 +39,7 @@ func templateApp(app string, inputFilePath string, appGroupDir string, lint bool return err } } - err = helmfileEngine.Template(app, inputFilePath, targeAppDir) + err = helmfileEngine.Template(app, namespace, inputFilePath, targeAppDir) if err != nil { return err } @@ -87,7 +87,7 @@ func applyAppGroup(group string, namespace string, outputDir string, appFilter s } } - err = templateApp(app, matchedAppFile, targetAppGroupDir, lint) + err = templateApp(app, namespace, matchedAppFile, targetAppGroupDir, lint) if err != nil { return fmt.Errorf("templating app: %w", err) } @@ -157,7 +157,7 @@ func init() { rootCmd.AddCommand(applyCmd) applyCmd.Flags().BoolP("lint", "l", false, "Lint temlate") - + applyCmd.Flags().BoolP("dry-run", "d", false, "Dry Run") applyCmd.Flags().StringP("namespace", "n", "", "Target namespace") applyCmd.MarkFlagRequired("namespace") diff --git a/pkg/template/helmfile.go b/pkg/template/helmfile.go index 5c5be30..7cacaae 100644 --- a/pkg/template/helmfile.go +++ b/pkg/template/helmfile.go @@ -32,10 +32,10 @@ func NewHelmFileEngine(Opts Opts, log logr.Logger) *HelmFileEngine { return &HelmFileEngine{Opts, log} } -func (e *HelmFileEngine) Template(name string, inputFilePath string, outputFilePath string) error { +func (e *HelmFileEngine) Template(name string,namespace string, inputFilePath string, outputFilePath string) error { inputArgs := append([]string{"--environment", e.Opts.Environment, - "--file", inputFilePath, "--state-values-set", fmt.Sprintf("app=%s", name), + "--file", inputFilePath, "--state-values-set", fmt.Sprintf("app=%s,namespace=%s", name,namespace), "template", "--output-dir", outputFilePath, fmt.Sprintf("--skip-deps=%t", e.Opts.SkipDeps)}, e.Opts.ExtraArgs...) cmd := exec.Command("helmfile", inputArgs...) diff --git a/realm/namespaces/_defaults.yaml b/realm/namespaces/_defaults.yaml index b1668a0..22122d7 100644 --- a/realm/namespaces/_defaults.yaml +++ b/realm/namespaces/_defaults.yaml @@ -1,8 +1,8 @@ repositories: # To use official "stable" charts a.k.a https://github.com/helm/charts/tree/master/stable - name: stable - url: https://kubernetes-charts.storage.googleapis.com + url: https://kubernetes-charts-incubator.storage.googleapis.com releases: - - name: dummy + - name: dummydummy chart: stable/raw \ No newline at end of file diff --git a/realm/namespaces/default/monitoring/dummy.yaml b/realm/namespaces/default/monitoring/dummy.yaml index 7b198f8..6210685 100644 --- a/realm/namespaces/default/monitoring/dummy.yaml +++ b/realm/namespaces/default/monitoring/dummy.yaml @@ -1,4 +1,6 @@ - +bases: +- ../../_defaults.yaml +- ../../../values/env/dev/{{.Environment.Values.namespace}}/values.yaml releases: - name: dummy diff --git a/realm/namespaces/default/monitoring/test.yaml b/realm/namespaces/default/monitoring/test.yaml index 3b3cf23..8df8a18 100644 --- a/realm/namespaces/default/monitoring/test.yaml +++ b/realm/namespaces/default/monitoring/test.yaml @@ -1,4 +1,7 @@ +bases: +- ../../_defaults.yaml +- ../../../values/env/dev/{{.Environment.Values.namespace}}/values.yaml releases: - name: test @@ -10,7 +13,7 @@ releases: apiVersion: v1 kind: ConfigMap metadata: - name: test + name: test-{{.Values.test}} diff --git a/realm/namespaces/default/testing/test1.yaml b/realm/namespaces/default/testing/test1.yaml index 7d41b2b..e8faecf 100644 --- a/realm/namespaces/default/testing/test1.yaml +++ b/realm/namespaces/default/testing/test1.yaml @@ -1,5 +1,7 @@ - +bases: +- ../../_defaults.yaml +- ../../../values/env/dev/{{.Environment.values.namespace}}/values.yaml releases: - name: test1 chart: incubator/raw diff --git a/realm/values/env/dev/default/values.yaml b/realm/values/env/dev/default/values.yaml new file mode 100644 index 0000000..3cb3ec0 --- /dev/null +++ b/realm/values/env/dev/default/values.yaml @@ -0,0 +1,4 @@ + +--- +values: +- test: 1