Skip to content

Commit 84afeba

Browse files
author
tbugfinder
committed
merge upstream
2 parents 3fd2ea0 + 1699f76 commit 84afeba

File tree

15 files changed

+282
-1097
lines changed

15 files changed

+282
-1097
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name: CI
33

44
env:
5-
VERSION_GO: '1.19.6'
6-
VERSION_HELM: 'v3.11.1'
5+
VERSION_GO: '1.19.8'
6+
VERSION_HELM: 'v3.11.3'
77

88
on:
99
pull_request:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
HELM_HOME ?= $(shell helm home)
22
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
33

4-
HELM_3_PLUGINS := $(shell bash -c 'eval $$(helm env); echo $$HELM_PLUGINS')
4+
HELM_3_PLUGINS := $(shell helm env HELM_PLUGINS)
55

66
PKG:= github.com/databus23/helm-diff/v3
77
LDFLAGS := -X $(PKG)/cmd.Version=$(VERSION)

README.md

Lines changed: 108 additions & 87 deletions
Large diffs are not rendered by default.

cmd/helm3.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
102102
if d.postRenderer != "" {
103103
flags = append(flags, "--post-renderer", d.postRenderer)
104104
}
105+
for _, arg := range d.postRendererArgs {
106+
flags = append(flags, "--post-renderer-args", arg)
107+
}
105108
// Helm automatically enable --reuse-values when there's no --set, --set-string, --set-values, --set-file present.
106109
// Let's simulate that in helm-diff.
107110
// See https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e

cmd/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func AddDiffOptions(f *pflag.FlagSet, o *diff.Options) {
1111
f.BoolVar(&o.ShowSecrets, "show-secrets", false, "do not redact secret values in the output")
1212
f.StringArrayVar(&o.SuppressedKinds, "suppress", []string{}, "allows suppression of the values listed in the diff output")
1313
f.IntVarP(&o.OutputContext, "context", "C", -1, "output NUM lines of context around changes")
14-
f.StringVar(&o.OutputFormat, "output", "diff", "Possible values: diff, simple, template. When set to \"template\", use the env var HELM_DIFF_TPL to specify the template.")
14+
f.StringVar(&o.OutputFormat, "output", "diff", "Possible values: diff, simple, template, dyff. When set to \"template\", use the env var HELM_DIFF_TPL to specify the template.")
1515
f.BoolVar(&o.StripTrailingCR, "strip-trailing-cr", false, "strip trailing carriage return on input")
1616
f.Float32VarP(&o.FindRenames, "find-renames", "D", 0, "Enable rename detection if set to any value greater than 0. If specified, the value denotes the maximum fraction of changed content as lines added + removed compared to total lines in a diff for considering it a rename. Only objects of the same Kind are attempted to be matched")
1717
}

cmd/release.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/spf13/cobra"
910
"k8s.io/helm/pkg/helm"
@@ -22,14 +23,16 @@ type release struct {
2223
}
2324

2425
const releaseCmdLongUsage = `
25-
This command compares the manifests details of a different releases created from the same chart
26+
This command compares the manifests details of a different releases created from the same chart.
27+
The release name may be specified using namespace/release syntax.
2628
2729
It can be used to compare the manifests of
2830
2931
- release1 with release2
3032
$ helm diff release [flags] release1 release2
3133
Example:
3234
$ helm diff release my-prod my-stage
35+
$ helm diff release prod/my-prod stage/my-stage
3336
`
3437

3538
func releaseCmd() *cobra.Command {
@@ -83,33 +86,45 @@ func releaseCmd() *cobra.Command {
8386
}
8487

8588
func (d *release) differentiateHelm3() error {
86-
namespace := os.Getenv("HELM_NAMESPACE")
8789
excludes := []string{helm3TestHook, helm2TestSuccessHook}
8890
if d.includeTests {
8991
excludes = []string{}
9092
}
91-
releaseResponse1, err := getRelease(d.releases[0], namespace)
93+
94+
namespace1 := os.Getenv("HELM_NAMESPACE")
95+
release1 := d.releases[0]
96+
if strings.Contains(release1, "/") {
97+
namespace1 = strings.Split(release1, "/")[0]
98+
release1 = strings.Split(release1, "/")[1]
99+
}
100+
releaseResponse1, err := getRelease(release1, namespace1)
92101
if err != nil {
93102
return err
94103
}
95-
releaseChart1, err := getChart(d.releases[0], namespace)
104+
releaseChart1, err := getChart(release1, namespace1)
96105
if err != nil {
97106
return err
98107
}
99108

100-
releaseResponse2, err := getRelease(d.releases[1], namespace)
109+
namespace2 := os.Getenv("HELM_NAMESPACE")
110+
release2 := d.releases[1]
111+
if strings.Contains(release2, "/") {
112+
namespace2 = strings.Split(release2, "/")[0]
113+
release2 = strings.Split(release2, "/")[1]
114+
}
115+
releaseResponse2, err := getRelease(release2, namespace2)
101116
if err != nil {
102117
return err
103118
}
104-
releaseChart2, err := getChart(d.releases[1], namespace)
119+
releaseChart2, err := getChart(release2, namespace2)
105120
if err != nil {
106121
return err
107122
}
108123

109124
if releaseChart1 == releaseChart2 {
110125
seenAnyChanges := diff.Releases(
111-
manifest.Parse(string(releaseResponse1), namespace, d.normalizeManifests, excludes...),
112-
manifest.Parse(string(releaseResponse2), namespace, d.normalizeManifests, excludes...),
126+
manifest.Parse(string(releaseResponse1), namespace1, d.normalizeManifests, excludes...),
127+
manifest.Parse(string(releaseResponse2), namespace2, d.normalizeManifests, excludes...),
113128
&d.Options,
114129
os.Stdout)
115130

cmd/revision.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This command compares the manifests details of a named release.
2828
2929
It can be used to compare the manifests of
3030
31-
- lastest REVISION with specified REVISION
31+
- latest REVISION with specified REVISION
3232
$ helm diff revision [flags] RELEASE REVISION1
3333
Example:
3434
$ helm diff revision my-release 2

cmd/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ The Helm Diff Plugin
1515
1616
* Shows a diff explaining what a helm upgrade would change:
1717
This fetches the currently deployed version of a release
18-
and compares it to a local chart plus values. This can be
18+
and compares it to a local chart plus values. This can be
1919
used visualize what changes a helm upgrade will perform.
2020
2121
* Shows a diff explaining what had changed between two revisions:
2222
This fetches previously deployed versions of a release
23-
and compares them. This can be used visualize what changes
23+
and compares them. This can be used visualize what changes
2424
were made during revision change.
2525
2626
* Shows a diff explaining what a helm rollback would change:
2727
This fetches the currently deployed version of a release
28-
and compares it to the previously deployed version of the release, that you
29-
want to rollback. This can be used visualize what changes a
28+
and compares it to the previously deployed version of the release, that you
29+
want to rollback. This can be used visualize what changes a
3030
helm rollback will perform.
3131
`
3232

cmd/upgrade.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type diffCmd struct {
5353
noHooks bool
5454
includeTests bool
5555
postRenderer string
56+
postRendererArgs []string
5657
install bool
5758
normalizeManifests bool
5859
threeWayMerge bool
@@ -206,6 +207,7 @@ func newChartCommand() *cobra.Command {
206207
f.BoolVar(&diff.disableOpenAPIValidation, "disable-openapi-validation", false, "disables rendered templates validation against the Kubernetes OpenAPI Schema")
207208
f.BoolVar(&diff.dryRun, "dry-run", false, "disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation")
208209
f.StringVar(&diff.postRenderer, "post-renderer", "", "the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path")
210+
f.StringArrayVar(&diff.postRendererArgs, "post-renderer-args", []string{}, "an argument to the post-renderer (can specify multiple)")
209211
f.BoolVar(&diff.normalizeManifests, "normalize-manifests", false, "normalize manifests before running diff to exclude style differences from the output")
210212

211213
AddDiffOptions(f, &diff.Options)
@@ -280,7 +282,7 @@ func (d *diffCmd) runHelm3() error {
280282

281283
currentSpecs := make(map[string]*manifest.MappingResult)
282284
if !newInstall && !d.dryRun {
283-
if !d.noHooks {
285+
if !d.noHooks && !d.threeWayMerge {
284286
hooks, err := getHooks(d.release, d.namespace)
285287
if err != nil {
286288
return err

diff/report.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package diff
33
import (
44
"errors"
55
"fmt"
6+
"github.com/gonvenience/ytbx"
7+
"github.com/homeport/dyff/pkg/dyff"
68
"io"
79
"log"
810
"os"
@@ -61,11 +63,52 @@ func (r *Report) setupReportFormat(format string) {
6163
setupTemplateReport(r)
6264
case "json":
6365
setupJSONReport(r)
66+
case "dyff":
67+
setupDyffReport(r)
6468
default:
6569
setupDiffReport(r)
6670
}
6771
}
6872

73+
func setupDyffReport(r *Report) {
74+
r.format.output = printDyffReport
75+
}
76+
77+
func printDyffReport(r *Report, to io.Writer) {
78+
currentFile, _ := os.CreateTemp("", "existing-values")
79+
defer os.Remove(currentFile.Name())
80+
newFile, _ := os.CreateTemp("", "new-values")
81+
defer os.Remove(newFile.Name())
82+
83+
for _, entry := range r.entries {
84+
_, _ = currentFile.WriteString("---\n")
85+
_, _ = newFile.WriteString("---\n")
86+
for _, record := range entry.diffs {
87+
switch record.Delta {
88+
case difflib.Common:
89+
_, _ = currentFile.WriteString(record.Payload + "\n")
90+
_, _ = newFile.WriteString(record.Payload + "\n")
91+
case difflib.LeftOnly:
92+
_, _ = currentFile.WriteString(record.Payload + "\n")
93+
case difflib.RightOnly:
94+
_, _ = newFile.WriteString(record.Payload + "\n")
95+
}
96+
}
97+
}
98+
_ = currentFile.Close()
99+
_ = newFile.Close()
100+
101+
currentInputFile, newInputFile, _ := ytbx.LoadFiles(currentFile.Name(), newFile.Name())
102+
103+
report, _ := dyff.CompareInputFiles(currentInputFile, newInputFile)
104+
reportWriter := &dyff.HumanReport{
105+
Report: report,
106+
OmitHeader: true,
107+
MinorChangeThreshold: 0.1,
108+
}
109+
_ = reportWriter.WriteReport(to)
110+
}
111+
69112
// addEntry: stores diff changes.
70113
func (r *Report) addEntry(key string, suppressedKinds []string, kind string, context int, diffs []difflib.DiffRecord, changeType string) {
71114
entry := ReportEntry{

0 commit comments

Comments
 (0)