Skip to content

Commit 312d45a

Browse files
authored
Add helm diff upgrade --dry-run to show install diff without cluster access (#230)
I found this to be handy when you want to review what is being installed outside of your terminal, on e.g. your CI/CD pipeline :)
1 parent 74f641b commit 312d45a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cmd/helm3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
102102
// Let's simulate that in helm-diff.
103103
// See https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e
104104
shouldDefaultReusingValues := isUpgrade && len(d.values) == 0 && len(d.stringValues) == 0 && len(d.valueFiles) == 0 && len(d.fileValues) == 0
105-
if (d.reuseValues || shouldDefaultReusingValues) && !d.resetValues {
105+
if (d.reuseValues || shouldDefaultReusingValues) && !d.resetValues && !d.dryRun {
106106
tmpfile, err := ioutil.TempFile("", "existing-values")
107107
if err != nil {
108108
return nil, err
@@ -126,7 +126,7 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
126126
flags = append(flags, "--set-file", fileValue)
127127
}
128128

129-
if !d.disableValidation {
129+
if !d.disableValidation && !d.dryRun {
130130
flags = append(flags, "--validate")
131131
}
132132

cmd/upgrade.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type diffCmd struct {
2222
devel bool
2323
disableValidation bool
2424
disableOpenAPIValidation bool
25+
dryRun bool
2526
namespace string // namespace to assume the release to be installed into. Defaults to the current kube config namespace.
2627
valueFiles valueFiles
2728
values []string
@@ -113,6 +114,7 @@ func newChartCommand() *cobra.Command {
113114
f.IntVarP(&diff.outputContext, "context", "C", -1, "output NUM lines of context around changes")
114115
f.BoolVar(&diff.disableValidation, "disable-validation", false, "disables rendered templates validation against the Kubernetes cluster you are currently pointing to. This is the same validation performed on an install")
115116
f.BoolVar(&diff.disableOpenAPIValidation, "disable-openapi-validation", false, "disables rendered templates validation against the Kubernetes OpenAPI Schema")
117+
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")
116118
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")
117119
f.StringVar(&diff.output, "output", "diff", "Possible values: diff, simple, json, template. When set to \"template\", use the env var HELM_DIFF_TPL to specify the template.")
118120
if !isHelm3() {
@@ -132,7 +134,14 @@ func (d *diffCmd) runHelm3() error {
132134
if err := compatibleHelm3Version(); err != nil {
133135
return err
134136
}
135-
releaseManifest, err := getRelease(d.release, d.namespace)
137+
138+
var releaseManifest []byte
139+
140+
var err error
141+
142+
if !d.dryRun {
143+
releaseManifest, err = getRelease(d.release, d.namespace)
144+
}
136145

137146
var newInstall bool
138147
if err != nil && strings.Contains(err.Error(), "release: not found") {
@@ -155,7 +164,7 @@ func (d *diffCmd) runHelm3() error {
155164
}
156165

157166
currentSpecs := make(map[string]*manifest.MappingResult)
158-
if !newInstall {
167+
if !newInstall && !d.dryRun {
159168
if !d.noHooks {
160169
hooks, err := getHooks(d.release, d.namespace)
161170
if err != nil {

0 commit comments

Comments
 (0)