@@ -14,8 +14,9 @@ import (
1414)
1515
1616var (
17- helmVersionRE = regexp .MustCompile (`Version:\s*"([^"]+)"` )
18- minHelmVersion = semver .MustParse ("v3.1.0-rc.1" )
17+ helmVersionRE = regexp .MustCompile (`Version:\s*"([^"]+)"` )
18+ minHelmVersion = semver .MustParse ("v3.1.0-rc.1" )
19+ // See https://github.com/helm/helm/pull/9426
1920 minHelmVersionWithDryRunLookupSupport = semver .MustParse ("v3.13.0" )
2021)
2122
@@ -131,7 +132,7 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
131132 // Let's simulate that in helm-diff.
132133 // See https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e
133134 shouldDefaultReusingValues := isUpgrade && len (d .values ) == 0 && len (d .stringValues ) == 0 && len (d .valueFiles ) == 0 && len (d .fileValues ) == 0
134- if (d .reuseValues || shouldDefaultReusingValues ) && ! d .resetValues && d .isRemoteAccessAllowed () {
135+ if (d .reuseValues || shouldDefaultReusingValues ) && ! d .resetValues && d .clusterAccessAllowed () {
135136 tmpfile , err := os .CreateTemp ("" , "existing-values" )
136137 if err != nil {
137138 return nil , err
@@ -192,36 +193,28 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
192193 filter func ([]byte ) []byte
193194 )
194195
196+ // `--dry-run=client` or `--dry-run=server`?
197+ //
198+ // Or what's the relationoship between helm-diff's --dry-run flag,
199+ // HELM_DIFF_UPGRADE_DRY_RUN env var and the helm upgrade --dry-run flag?
200+ //
201+ // Read on to find out.
195202 if d .useUpgradeDryRun {
196- //
197- // # `--dry-run=client` or `--dry-run=server`?
198- //
199- // Or what's the relationoship between helm-diff's --dry-run flag,
200- // HELM_DIFF_UPGRADE_DRY_RUN env var and the helm upgrade --dry-run flag?
201- //
202- // If the program reaches here,
203- // we are sure that the user wants to user the `helm upgrade --dry-run` command
204- // for generating the manifests to be diffed.
205- //
206- // However, which dry-run mode to use is still not clear.
207- //
208- // For compatibility with the old and new helm-diff options,
209- // old and new helm, we assume that the user wants to use the `--dry-run=client` mode
210- // if helm-diff has been invoked with any of the following flags:
211- //
212- // * --dry-run
213- // * --dry-run=""
214- // * --dry-run=client
215- //
216- // Otherwise, we assume that the user wants to use the `--dry-run=server` mode.
217- //
218-
219203 if d .isAllowUnreleased () {
220204 // Otherwise you get the following error when this is a diff for a new install
221205 // Error: UPGRADE FAILED: "$RELEASE_NAME" has no deployed releases
222206 flags = append (flags , "--install" )
223207 }
224208
209+ // If the program reaches here,
210+ // we are sure that the user wants to user the `helm upgrade --dry-run` command
211+ // for generating the manifests to be diffed.
212+ //
213+ // So the question is only whether to use `--dry-run=client` or `--dry-run=server`.
214+ //
215+ // As HELM_DIFF_UPGRADE_DRY_RUN is there for producing more complete and correct diff results,
216+ // we use --dry-run=server if the version of helm supports it.
217+ // Otherwise, we use --dry-run=client, as that's the best we can do.
225218 if useDryRunService , err := isHelmVersionAtLeast (minHelmVersionWithDryRunLookupSupport ); err == nil && useDryRunService {
226219 flags = append (flags , "--dry-run=server" )
227220 } else {
@@ -232,7 +225,7 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
232225 return extractManifestFromHelmUpgradeDryRunOutput (s , d .noHooks )
233226 }
234227 } else {
235- if ! d .disableValidation && d .isRemoteAccessAllowed () {
228+ if ! d .disableValidation && d .clusterAccessAllowed () {
236229 flags = append (flags , "--validate" )
237230 }
238231
@@ -251,12 +244,28 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
251244 // To keep the full compatibility with older helm-diff versions,
252245 // we pass --dry-run to `helm template` only if Helm is greater than v3.13.0.
253246 if useDryRunService , err := isHelmVersionAtLeast (minHelmVersionWithDryRunLookupSupport ); err == nil && useDryRunService {
247+ // However, which dry-run mode to use is still not clear.
248+ //
249+ // For compatibility with the old and new helm-diff options,
250+ // old and new helm, we assume that the user wants to use the older `helm template --dry-run=client` mode
251+ // if helm-diff has been invoked with any of the following flags:
252+ //
253+ // * no dry-run flags (to be consistent with helm-template)
254+ // * --dry-run
255+ // * --dry-run=""
256+ // * --dry-run=client
257+ //
258+ // and the newer `helm template --dry-run=server` mode when invoked with:
259+ //
260+ // * --dry-run=server
261+ //
262+ // Any other values should result in errors.
263+ //
254264 // See the fllowing link for more details:
255265 // - https://github.com/databus23/helm-diff/pull/458
256266 // - https://github.com/helm/helm/pull/9426#issuecomment-1501005666
257267 if d .dryRunMode == "server" {
258- //
259- // # This is for security reasons!
268+ // This is for security reasons!
260269 //
261270 // We give helm-template the additional cluster access for the helm `lookup` function
262271 // only if the user has explicitly requested it by --dry-run=server,
@@ -266,6 +275,10 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
266275 // full cluster-access via helm-template --dry-run=server!
267276 flags = append (flags , "--dry-run=server" )
268277 } else {
278+ // Since helm-diff 3.9.0 and helm 3.13.0, we pass --dry-run=client to `helm template` by default.
279+ // This doesn't make any difference for helm-diff itself,
280+ // because helm-template w/o flags is equivalent to helm-template --dry-run=client.
281+ // See https://github.com/helm/helm/pull/9426#discussion_r1181397259
269282 flags = append (flags , "--dry-run=client" )
270283 }
271284 }
0 commit comments