Repository: roboll/helmfile
Pull request #1746 (2021-03-30 09:49:21)

add documentation
relates to #1743, #1744, #1734 



Patch:
diff --git a/README.md b/README.md
index 94701d1..0d45c43 100644
--- a/README.md
+++ b/README.md
@@ -475,6 +475,7 @@ COMMANDS:
    test          test releases from state file (helm test)
    build         output compiled helmfile state(s) as YAML
    list          list releases defined in state file
+   fetch         fetch charts from state file
    version       Show the version for Helmfile.
    help, h       Shows a list of commands or help for one command
 
@@ -572,6 +573,11 @@ Use `--cleanup` to delete pods upon completion.
 
 The `helmfile lint` sub-command runs a `helm lint` across all of the charts/releases defined in the manifest. Non local charts will be fetched into a temporary folder which will be deleted once the task is completed.
 
+### fetch
+
+The `helmfile fetch` sub-command downloads or copies local charts to a local directory for debug purpose. The local directory
+must be specified with `--output-dir`.
+
 ## Paths Overview
 
 Using manifest files in conjunction with command line argument can be a bit confusing.
diff --git a/docs/writing-helmfile.md b/docs/writing-helmfile.md
index 792be58..f798238 100644
--- a/docs/writing-helmfile.md
+++ b/docs/writing-helmfile.md
@@ -2,6 +2,23 @@
 
 This guide covers the Helmfile’s considered patterns for writing advanced helmfiles. It focuses on how helmfile should be structured and executed.
 
+## Helmfile .Values vs Helm .Values
+
+Templating engine of Helmfile uses the same pipeline name `.Values` as Helm, so in some use-cases `.Vaues` of Helmfile and
+Helm can be seen in the same file. To distinguish these two kinds of `.Values`, Helmfile provides an alias `.StateValues`
+for its `.Values`.
+
+```
+app:
+  project: {{.Environmont.Name}}-{{.StateValues.project}} # Same as {{.Environmont.Name}}-{{.Values.project}}
+
+{{`
+extraEnvVars:
+- name: APP_PROJECT
+  value: {{.Values.app.project}}
+`}}
+```
+
 ## Missing keys and Default values
 
 helmfile tries its best to inform users for noticing potential mistakes.
@@ -314,7 +331,7 @@ helmDefaults:
   force: true
 ```
 
-Each go template is rendered in the context where `.Values` is inherited from the previous part. 
+Each go template is rendered in the context where `.Values` is inherited from the previous part.
 
 So in `mydefaults.yaml.gotmpl`, both `.Values.kubeContext` and `.Values.wait` are valid as they do exist in the environment values inherited from the previous part(=the first part) of your `helmfile.yaml.gotmpl`, and therefore the template is rendered to:
 
diff --git a/main.go b/main.go
index 8d58863..a708e4b 100644
--- a/main.go
+++ b/main.go
@@ -200,6 +200,10 @@ func main() {
 					Name:  "suppress-secrets",
 					Usage: "suppress secrets in the output. highly recommended to specify on CI/CD use-cases",
 				},
+				cli.BoolFlag{
+					Name:  "show-secrets",
+					Usage: "do not redact secret values in the output. should be used for debug purpose only",
+				},
 				cli.IntFlag{
 					Name:  "concurrency",
 					Value: 0,
@@ -439,6 +443,10 @@ func main() {
 					Name:  "suppress-secrets",
 					Usage: "suppress secrets in the diff output. highly recommended to specify on CI/CD use-cases",
 				},
+				cli.BoolFlag{
+					Name:  "show-secrets",
+					Usage: "do not redact secret values in the diff output. should be used for debug purpose only",
+				},
 				cli.BoolFlag{
 					Name:  "suppress-diff",
 					Usage: "suppress diff in the output. Usable in new installs",
@@ -713,6 +721,10 @@ func (c configImpl) SuppressSecrets() bool {
 	return c.c.Bool("suppress-secrets")
 }
 
+func (c configImpl) ShowSecrets() bool {
+	return c.c.Bool("show-secrets")
+}
+
 func (c configImpl) SuppressDiff() bool {
 	return c.c.Bool("suppress-diff")
 }
diff --git a/pkg/app/config.go b/pkg/app/config.go
index db348af..2bbe240 100644
--- a/pkg/app/config.go
+++ b/pkg/app/config.go
@@ -45,6 +45,7 @@ type ApplyConfigProvider interface {
 	IncludeTests() bool
 
 	SuppressSecrets() bool
+	ShowSecrets() bool
 	SuppressDiff() bool
 
 	DetailedExitcode() bool
@@ -84,6 +85,7 @@ type DiffConfigProvider interface {
 	IncludeTests() bool
 
 	SuppressSecrets() bool
+	ShowSecrets() bool
 	SuppressDiff() bool
 
 	DetailedExitcode() bool
diff --git a/pkg/app/run.go b/pkg/app/run.go
index a293148..298bcb2 100644
--- a/pkg/app/run.go
+++ b/pkg/app/run.go
@@ -222,7 +222,7 @@ func (run *Run) diff(triggerCleanupEvent bool, detailedExitCode bool, c DiffConf
 
 	// TODO Better way to detect diff on only filtered releases
 	{
-		changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.IncludeTests(), c.SuppressSecrets(), c.SuppressDiff(), triggerCleanupEvent, diffOpts)
+		changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.IncludeTests(), c.SuppressSecrets(), c.ShowSecrets(), c.SuppressDiff(), triggerCleanupEvent, diffOpts)
 
 		var err error
 		deletingReleases, err = st.DetectReleasesToBeDeletedForSync(helm, st.Releases)
diff --git a/pkg/state/state.go b/pkg/state/state.go
index a8839a8..066832f 100644
--- a/pkg/state/state.go
+++ b/pkg/state/state.go
@@ -1525,7 +1525,7 @@ type diffPrepareResult struct {
 	upgradeDueToSkippedDiff bool
 }
 
-func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, includeTests, suppressSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) {
+func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, includeTests, suppressSecrets bool, showSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) {
 	opts := &DiffOpts{}
 	for _, o := range opt {
 		o.Apply(opts)
@@ -1630,6 +1630,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
 					flags = append(flags, "--suppress-secrets")
 				}
 
+				if showSecrets {
+					flags = append(flags, "--show-secrets")
+				}
+
 				if opts.NoColor {
 					flags = append(flags, "--no-color")
 				}
@@ -1735,13 +1739,13 @@ type DiffOpt interface{ Apply(*DiffOpts) }
 // For example, terraform-provider-helmfile runs a helmfile-diff on `terraform plan` and another on `terraform apply`.
 // `terraform`, by design, fails when helmfile-diff outputs were not equivalent.
 // Stabilized helmfile-diff output rescues that.
-func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, includeTests, suppressSecrets, suppressDiff, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) {
+func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, includeTests, suppressSecrets, showSecrets, suppressDiff, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) {
 	opts := &DiffOpts{}
 	for _, o := range opt {
 		o.Apply(opts)
 	}
 
-	preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppressSecrets, opts)
+	preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppressSecrets, showSecrets, opts)
 
 	defer func() {
 		if opts.SkipCleanup {
diff --git a/pkg/state/state_exec_tmpl.go b/pkg/state/state_exec_tmpl.go
index 7c62717..023287f 100644
--- a/pkg/state/state_exec_tmpl.go
+++ b/pkg/state/state_exec_tmpl.go
@@ -17,7 +17,7 @@ func (st *HelmState) Values() map[string]interface{} {
 }
 
 func (st *HelmState) createReleaseTemplateData(release *ReleaseSpec, vals map[string]interface{}) releaseTemplateData {
-	return releaseTemplateData{
+	tmplData := releaseTemplateData{
 		Environment: st.Env,
 		Namespace:   st.OverrideNamespace,
 		Values:      vals,
@@ -28,6 +28,8 @@ func (st *HelmState) createReleaseTemplateData(release *ReleaseSpec, vals map[st
 			Labels:    release.Labels,
 		},
 	}
+	tmplData.StateValues = &tmplData.Values
+	return tmplData
 }
 
 func getBoolRefFromStringTemplate(templateRef string) (*bool, error) {
diff --git a/pkg/state/types.go b/pkg/state/types.go
index 2b76b8e..9e28c84 100644
--- a/pkg/state/types.go
+++ b/pkg/state/types.go
@@ -28,7 +28,8 @@ type releaseTemplateData struct {
 	// It contains a subset of ReleaseSpec that is known to be useful to dynamically render values.
 	Release releaseTemplateDataRelease
 	// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
-	Values map[string]interface{}
+	Values      map[string]interface{}
+	StateValues *map[string]interface{}
 	// Namespace is HelmState.OverrideNamespace.
 	// You should better use Release.Namespace as it might work as you'd expect even if OverrideNamespace is not set.
 	// See releaseTemplateDataRelease.Namespace for more information.


Test patch:
diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go
index b1c2e97..213ae93 100644
--- a/pkg/app/app_test.go
+++ b/pkg/app/app_test.go
@@ -2308,6 +2308,7 @@ type applyConfig struct {
 	skipDeps          bool
 	includeTests      bool
 	suppressSecrets   bool
+	showSecrets       bool
 	suppressDiff      bool
 	noColor           bool
 	context           int
@@ -2360,6 +2361,10 @@ func (a applyConfig) SuppressSecrets() bool {
 	return a.suppressSecrets
 }
 
+func (a applyConfig) ShowSecrets() bool {
+	return a.showSecrets
+}
+
 func (a applyConfig) SuppressDiff() bool {
 	return a.suppressDiff
 }
diff --git a/pkg/app/diff_test.go b/pkg/app/diff_test.go
index 8b5127e..90eade1 100644
--- a/pkg/app/diff_test.go
+++ b/pkg/app/diff_test.go
@@ -23,6 +23,7 @@ type diffConfig struct {
 	skipDeps          bool
 	includeTests      bool
 	suppressSecrets   bool
+	showSecrets       bool
 	suppressDiff      bool
 	noColor           bool
 	context           int
@@ -60,6 +61,10 @@ func (a diffConfig) SuppressSecrets() bool {
 	return a.suppressSecrets
 }
 
+func (a diffConfig) ShowSecrets() bool {
+	return a.showSecrets
+}
+
 func (a diffConfig) SuppressDiff() bool {
 	return a.suppressDiff
 }
diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go
index 4e426fe..06db9c2 100644
--- a/pkg/state/state_test.go
+++ b/pkg/state/state_test.go
@@ -1570,7 +1570,7 @@ func TestHelmState_DiffReleases(t *testing.T) {
 				valsRuntime:    valsRuntime,
 				RenderedValues: map[string]interface{}{},
 			}
-			_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false)
+			_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false, false)
 			if errs != nil && len(errs) > 0 {
 				t.Errorf("unexpected error: %v", errs)
 			}
@@ -1741,7 +1741,7 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) {
 `,
 			})
 			state = injectFs(state, testfs)
-			if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false); errs != nil && len(errs) > 0 {
+			if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false, false); errs != nil && len(errs) > 0 {
 				t.Errorf("unexpected errors: %v", errs)
 			}