Skip to content

Commit 83189db

Browse files
astorathAndrey Tuzhilin
and
Andrey Tuzhilin
authored
Enable helmfile-diff to pass the output format to helm-diff (roboll#1784)
* tests: fix vagrant test run * feat: added an option to specify the different diff output format * renamed diff-output to output * renamed diff-output to output Co-authored-by: Andrey Tuzhilin <[email protected]>
1 parent 28ade19 commit 83189db

File tree

9 files changed

+40
-3
lines changed

9 files changed

+40
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ vendor/
99
*.log
1010
.vagrant/
1111
*.lock
12+
test/integration/.gnupg/

Vagrantfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Vagrant.configure("2") do |config|
2-
config.vm.box = "ubuntu/xenial64"
2+
config.vm.box = "ubuntu/focal64"
33
config.vm.hostname = "minikube.box"
44
config.vm.provision :shell, privileged: false,
55
inline: <<-EOS
66
set -e
77
sudo apt-get update
8-
sudo apt-get install -y make docker.io=18.09.7-*
8+
sudo apt-get install -y make docker.io
99
sudo systemctl start docker
1010
sudo usermod -G docker $USER
1111
cd /vagrant/.circleci

main.go

+14
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ func main() {
225225
Value: 0,
226226
Usage: "output NUM lines of context around changes",
227227
},
228+
cli.StringFlag{
229+
Name: "output",
230+
Value: "",
231+
Usage: "output format for diff plugin",
232+
},
228233
},
229234
Action: action(func(a *app.App, c configImpl) error {
230235
return a.Diff(c)
@@ -441,6 +446,11 @@ func main() {
441446
Value: 0,
442447
Usage: "output NUM lines of context around changes",
443448
},
449+
cli.StringFlag{
450+
Name: "output",
451+
Value: "",
452+
Usage: "output format for diff plugin",
453+
},
444454
cli.BoolFlag{
445455
Name: "detailed-exitcode",
446456
Usage: "return a non-zero exit code 2 instead of 0 when there were changes detected AND the changes are synced successfully",
@@ -855,6 +865,10 @@ func (c configImpl) Context() int {
855865
return c.c.Int("context")
856866
}
857867

868+
func (c configImpl) DiffOutput() string {
869+
return c.c.String("output")
870+
}
871+
858872
func (c configImpl) SkipCleanup() bool {
859873
return c.c.Bool("skip-cleanup")
860874
}

pkg/app/app.go

+2
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
11531153
diffOpts := &state.DiffOpts{
11541154
NoColor: c.NoColor(),
11551155
Context: c.Context(),
1156+
Output: c.DiffOutput(),
11561157
Set: c.Set(),
11571158
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
11581159
SkipDiffOnInstall: c.SkipDiffOnInstall(),
@@ -1378,6 +1379,7 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error)
13781379

13791380
opts := &state.DiffOpts{
13801381
Context: c.Context(),
1382+
Output: c.DiffOutput(),
13811383
NoColor: c.NoColor(),
13821384
Set: c.Set(),
13831385
}

pkg/app/app_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,7 @@ type applyConfig struct {
23312331
suppressDiff bool
23322332
noColor bool
23332333
context int
2334+
diffOutput string
23342335
concurrency int
23352336
detailedExitcode bool
23362337
interactive bool
@@ -2408,6 +2409,10 @@ func (a applyConfig) Context() int {
24082409
return a.context
24092410
}
24102411

2412+
func (a applyConfig) DiffOutput() string {
2413+
return a.diffOutput
2414+
}
2415+
24112416
func (a applyConfig) Concurrency() int {
24122417
return a.concurrency
24132418
}

pkg/app/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type ApplyConfigProvider interface {
5454

5555
NoColor() bool
5656
Context() int
57+
DiffOutput() string
5758

5859
RetainValuesFiles() bool
5960
SkipCleanup() bool
@@ -104,6 +105,7 @@ type DiffConfigProvider interface {
104105
DetailedExitcode() bool
105106
NoColor() bool
106107
Context() int
108+
DiffOutput() string
107109

108110
concurrencyConfig
109111
}

pkg/app/diff_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type diffConfig struct {
3232
suppressDiff bool
3333
noColor bool
3434
context int
35+
diffOutput string
3536
concurrency int
3637
detailedExitcode bool
3738
interactive bool
@@ -94,6 +95,10 @@ func (a diffConfig) Context() int {
9495
return a.context
9596
}
9697

98+
func (a diffConfig) DiffOutput() string {
99+
return a.diffOutput
100+
}
101+
97102
func (a diffConfig) Concurrency() int {
98103
return a.concurrency
99104
}

pkg/state/state.go

+5
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
16641664
flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context))
16651665
}
16661666

1667+
if opts.Output != "" {
1668+
flags = append(flags, "--output", fmt.Sprintf("%s", opts.Output))
1669+
}
1670+
16671671
if opts.Set != nil {
16681672
for _, s := range opts.Set {
16691673
flags = append(flags, "--set", s)
@@ -1739,6 +1743,7 @@ func (st *HelmState) createHelmContextWithWriter(spec *ReleaseSpec, w io.Writer)
17391743

17401744
type DiffOpts struct {
17411745
Context int
1746+
Output string
17421747
NoColor bool
17431748
Set []string
17441749

test/integration/run.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export HELM_HOME="${HELM_DATA_HOME}"
2626
export HELM_PLUGINS="${HELM_DATA_HOME}/plugins"
2727
export HELM_CONFIG_HOME="${helm_dir}/config"
2828
HELM_SECRETS_VERSION=3.5.0
29-
HELM_DIFF_VERSION=3.0.0-rc.7
29+
HELM_DIFF_VERSION=3.1.3
3030
export GNUPGHOME="${PWD}/${dir}/.gnupg"
3131
export SOPS_PGP_FP="B2D6D7BBEC03B2E66571C8C00AD18E16CFDEF700"
3232

@@ -95,6 +95,9 @@ bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcod
9595
info "Diffing ${dir}/happypath.yaml with limited context"
9696
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
9797

98+
info "Diffing ${dir}/happypath.yaml with altered output"
99+
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --output simple --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
100+
98101
info "Templating ${dir}/happypath.yaml"
99102
rm -rf ${dir}/tmp
100103
${helmfile} -f ${dir}/happypath.yaml --debug template --output-dir tmp

0 commit comments

Comments
 (0)