Skip to content

Commit

Permalink
add namespace to state vals for app
Browse files Browse the repository at this point in the history
  • Loading branch information
arttii committed Jan 13, 2021
1 parent 4621259 commit d342612
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions pkg/template/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions realm/namespaces/_defaults.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion realm/namespaces/default/monitoring/dummy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

bases:
- ../../_defaults.yaml
- ../../../values/env/dev/{{.Environment.Values.namespace}}/values.yaml

releases:
- name: dummy
Expand Down
5 changes: 4 additions & 1 deletion realm/namespaces/default/monitoring/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

bases:
- ../../_defaults.yaml
- ../../../values/env/dev/{{.Environment.Values.namespace}}/values.yaml

releases:
- name: test
Expand All @@ -10,7 +13,7 @@ releases:
apiVersion: v1
kind: ConfigMap
metadata:
name: test
name: test-{{.Values.test}}


Expand Down
4 changes: 3 additions & 1 deletion realm/namespaces/default/testing/test1.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


bases:
- ../../_defaults.yaml
- ../../../values/env/dev/{{.Environment.values.namespace}}/values.yaml
releases:
- name: test1
chart: incubator/raw
Expand Down
4 changes: 4 additions & 0 deletions realm/values/env/dev/default/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

---
values:
- test: 1

0 comments on commit d342612

Please sign in to comment.