Enable `helmfile-diff` to pass the output format to helm-diff (#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 <andrey@zelf.co>
This commit is contained in:
parent
28ade19419
commit
83189dbad3
|
|
@ -9,3 +9,4 @@ vendor/
|
||||||
*.log
|
*.log
|
||||||
.vagrant/
|
.vagrant/
|
||||||
*.lock
|
*.lock
|
||||||
|
test/integration/.gnupg/
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.box = "ubuntu/xenial64"
|
config.vm.box = "ubuntu/focal64"
|
||||||
config.vm.hostname = "minikube.box"
|
config.vm.hostname = "minikube.box"
|
||||||
config.vm.provision :shell, privileged: false,
|
config.vm.provision :shell, privileged: false,
|
||||||
inline: <<-EOS
|
inline: <<-EOS
|
||||||
set -e
|
set -e
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y make docker.io=18.09.7-*
|
sudo apt-get install -y make docker.io
|
||||||
sudo systemctl start docker
|
sudo systemctl start docker
|
||||||
sudo usermod -G docker $USER
|
sudo usermod -G docker $USER
|
||||||
cd /vagrant/.circleci
|
cd /vagrant/.circleci
|
||||||
|
|
|
||||||
14
main.go
14
main.go
|
|
@ -225,6 +225,11 @@ func main() {
|
||||||
Value: 0,
|
Value: 0,
|
||||||
Usage: "output NUM lines of context around changes",
|
Usage: "output NUM lines of context around changes",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "output",
|
||||||
|
Value: "",
|
||||||
|
Usage: "output format for diff plugin",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: action(func(a *app.App, c configImpl) error {
|
Action: action(func(a *app.App, c configImpl) error {
|
||||||
return a.Diff(c)
|
return a.Diff(c)
|
||||||
|
|
@ -441,6 +446,11 @@ func main() {
|
||||||
Value: 0,
|
Value: 0,
|
||||||
Usage: "output NUM lines of context around changes",
|
Usage: "output NUM lines of context around changes",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "output",
|
||||||
|
Value: "",
|
||||||
|
Usage: "output format for diff plugin",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "detailed-exitcode",
|
Name: "detailed-exitcode",
|
||||||
Usage: "return a non-zero exit code 2 instead of 0 when there were changes detected AND the changes are synced successfully",
|
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 {
|
||||||
return c.c.Int("context")
|
return c.c.Int("context")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configImpl) DiffOutput() string {
|
||||||
|
return c.c.String("output")
|
||||||
|
}
|
||||||
|
|
||||||
func (c configImpl) SkipCleanup() bool {
|
func (c configImpl) SkipCleanup() bool {
|
||||||
return c.c.Bool("skip-cleanup")
|
return c.c.Bool("skip-cleanup")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1153,6 +1153,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
|
||||||
diffOpts := &state.DiffOpts{
|
diffOpts := &state.DiffOpts{
|
||||||
NoColor: c.NoColor(),
|
NoColor: c.NoColor(),
|
||||||
Context: c.Context(),
|
Context: c.Context(),
|
||||||
|
Output: c.DiffOutput(),
|
||||||
Set: c.Set(),
|
Set: c.Set(),
|
||||||
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
|
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
|
||||||
SkipDiffOnInstall: c.SkipDiffOnInstall(),
|
SkipDiffOnInstall: c.SkipDiffOnInstall(),
|
||||||
|
|
@ -1378,6 +1379,7 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error)
|
||||||
|
|
||||||
opts := &state.DiffOpts{
|
opts := &state.DiffOpts{
|
||||||
Context: c.Context(),
|
Context: c.Context(),
|
||||||
|
Output: c.DiffOutput(),
|
||||||
NoColor: c.NoColor(),
|
NoColor: c.NoColor(),
|
||||||
Set: c.Set(),
|
Set: c.Set(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2331,6 +2331,7 @@ type applyConfig struct {
|
||||||
suppressDiff bool
|
suppressDiff bool
|
||||||
noColor bool
|
noColor bool
|
||||||
context int
|
context int
|
||||||
|
diffOutput string
|
||||||
concurrency int
|
concurrency int
|
||||||
detailedExitcode bool
|
detailedExitcode bool
|
||||||
interactive bool
|
interactive bool
|
||||||
|
|
@ -2408,6 +2409,10 @@ func (a applyConfig) Context() int {
|
||||||
return a.context
|
return a.context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a applyConfig) DiffOutput() string {
|
||||||
|
return a.diffOutput
|
||||||
|
}
|
||||||
|
|
||||||
func (a applyConfig) Concurrency() int {
|
func (a applyConfig) Concurrency() int {
|
||||||
return a.concurrency
|
return a.concurrency
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ type ApplyConfigProvider interface {
|
||||||
|
|
||||||
NoColor() bool
|
NoColor() bool
|
||||||
Context() int
|
Context() int
|
||||||
|
DiffOutput() string
|
||||||
|
|
||||||
RetainValuesFiles() bool
|
RetainValuesFiles() bool
|
||||||
SkipCleanup() bool
|
SkipCleanup() bool
|
||||||
|
|
@ -104,6 +105,7 @@ type DiffConfigProvider interface {
|
||||||
DetailedExitcode() bool
|
DetailedExitcode() bool
|
||||||
NoColor() bool
|
NoColor() bool
|
||||||
Context() int
|
Context() int
|
||||||
|
DiffOutput() string
|
||||||
|
|
||||||
concurrencyConfig
|
concurrencyConfig
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ type diffConfig struct {
|
||||||
suppressDiff bool
|
suppressDiff bool
|
||||||
noColor bool
|
noColor bool
|
||||||
context int
|
context int
|
||||||
|
diffOutput string
|
||||||
concurrency int
|
concurrency int
|
||||||
detailedExitcode bool
|
detailedExitcode bool
|
||||||
interactive bool
|
interactive bool
|
||||||
|
|
@ -94,6 +95,10 @@ func (a diffConfig) Context() int {
|
||||||
return a.context
|
return a.context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a diffConfig) DiffOutput() string {
|
||||||
|
return a.diffOutput
|
||||||
|
}
|
||||||
|
|
||||||
func (a diffConfig) Concurrency() int {
|
func (a diffConfig) Concurrency() int {
|
||||||
return a.concurrency
|
return a.concurrency
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1664,6 +1664,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
|
||||||
flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context))
|
flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Output != "" {
|
||||||
|
flags = append(flags, "--output", fmt.Sprintf("%s", opts.Output))
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Set != nil {
|
if opts.Set != nil {
|
||||||
for _, s := range opts.Set {
|
for _, s := range opts.Set {
|
||||||
flags = append(flags, "--set", s)
|
flags = append(flags, "--set", s)
|
||||||
|
|
@ -1739,6 +1743,7 @@ func (st *HelmState) createHelmContextWithWriter(spec *ReleaseSpec, w io.Writer)
|
||||||
|
|
||||||
type DiffOpts struct {
|
type DiffOpts struct {
|
||||||
Context int
|
Context int
|
||||||
|
Output string
|
||||||
NoColor bool
|
NoColor bool
|
||||||
Set []string
|
Set []string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export HELM_HOME="${HELM_DATA_HOME}"
|
||||||
export HELM_PLUGINS="${HELM_DATA_HOME}/plugins"
|
export HELM_PLUGINS="${HELM_DATA_HOME}/plugins"
|
||||||
export HELM_CONFIG_HOME="${helm_dir}/config"
|
export HELM_CONFIG_HOME="${helm_dir}/config"
|
||||||
HELM_SECRETS_VERSION=3.5.0
|
HELM_SECRETS_VERSION=3.5.0
|
||||||
HELM_DIFF_VERSION=3.0.0-rc.7
|
HELM_DIFF_VERSION=3.1.3
|
||||||
export GNUPGHOME="${PWD}/${dir}/.gnupg"
|
export GNUPGHOME="${PWD}/${dir}/.gnupg"
|
||||||
export SOPS_PGP_FP="B2D6D7BBEC03B2E66571C8C00AD18E16CFDEF700"
|
export SOPS_PGP_FP="B2D6D7BBEC03B2E66571C8C00AD18E16CFDEF700"
|
||||||
|
|
||||||
|
|
@ -95,6 +95,9 @@ bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcod
|
||||||
info "Diffing ${dir}/happypath.yaml with limited context"
|
info "Diffing ${dir}/happypath.yaml with limited context"
|
||||||
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
|
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
|
||||||
|
|
||||||
|
info "Diffing ${dir}/happypath.yaml with altered output"
|
||||||
|
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --output simple --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
|
||||||
|
|
||||||
info "Templating ${dir}/happypath.yaml"
|
info "Templating ${dir}/happypath.yaml"
|
||||||
rm -rf ${dir}/tmp
|
rm -rf ${dir}/tmp
|
||||||
${helmfile} -f ${dir}/happypath.yaml --debug template --output-dir tmp
|
${helmfile} -f ${dir}/happypath.yaml --debug template --output-dir tmp
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue