mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-22 11:26:58 +02:00
feat: add --skip-diff-validation-on-install CLI flag (#2728)
Signed-off-by: Richter <h.richter@sap.com>
This commit is contained in:
+7
-6
@@ -2990,7 +2990,7 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
|
||||
}
|
||||
|
||||
var disableValidation bool
|
||||
if release.DisableValidationOnInstall != nil && *release.DisableValidationOnInstall {
|
||||
if (release.DisableValidationOnInstall != nil && *release.DisableValidationOnInstall) || opt.SkipDiffValidationOnInstall {
|
||||
installed, err := isInstalled(release)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
@@ -3090,11 +3090,12 @@ type DiffOpts struct {
|
||||
Color bool
|
||||
// NoColor forces disabling the color output on helm-diff.
|
||||
// If this is true, Color has no effect.
|
||||
NoColor bool
|
||||
Set []string
|
||||
SkipCleanup bool
|
||||
SkipDiffOnInstall bool
|
||||
DiffArgs string
|
||||
NoColor bool
|
||||
Set []string
|
||||
SkipCleanup bool
|
||||
SkipDiffOnInstall bool
|
||||
SkipDiffValidationOnInstall bool
|
||||
DiffArgs string
|
||||
// TemplateArgs are extra args appended to the helm template/diff rendering
|
||||
// (e.g. "--dry-run=server" to enable the helm lookup function during `helmfile
|
||||
// apply`/`diff`, which render via helm-diff). See issue #1833.
|
||||
|
||||
@@ -4268,6 +4268,87 @@ func TestDiffpareSyncReleases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareDiffReleases_SkipDiffValidationOnInstall(t *testing.T) {
|
||||
installedListOutput := "NAME\tNAMESPACE\tREVISION\tSTATUS\nfoo\tdefault\t1\tdeployed"
|
||||
listFlags := "--uninstalling --deployed --failed --pending"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
skipDiffValidationOnInstall bool
|
||||
perReleaseDisableValidation bool
|
||||
installed bool
|
||||
wantDisableValidation bool
|
||||
}{
|
||||
{
|
||||
name: "flag-set-not-installed",
|
||||
skipDiffValidationOnInstall: true,
|
||||
installed: false,
|
||||
wantDisableValidation: true,
|
||||
},
|
||||
{
|
||||
name: "flag-set-already-installed",
|
||||
skipDiffValidationOnInstall: true,
|
||||
installed: true,
|
||||
wantDisableValidation: false,
|
||||
},
|
||||
{
|
||||
name: "flag-not-set-not-installed",
|
||||
skipDiffValidationOnInstall: false,
|
||||
installed: false,
|
||||
wantDisableValidation: false,
|
||||
},
|
||||
{
|
||||
name: "per-release-flag-not-installed",
|
||||
perReleaseDisableValidation: true,
|
||||
installed: false,
|
||||
wantDisableValidation: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
release := ReleaseSpec{
|
||||
Name: "foo",
|
||||
Chart: "stable/foo",
|
||||
}
|
||||
if tt.perReleaseDisableValidation {
|
||||
release.DisableValidationOnInstall = boolValue(true)
|
||||
}
|
||||
st := &HelmState{
|
||||
ReleaseSetSpec: ReleaseSetSpec{
|
||||
Releases: []ReleaseSpec{release},
|
||||
HelmDefaults: HelmSpec{},
|
||||
},
|
||||
logger: logger,
|
||||
valsRuntime: valsRuntime,
|
||||
}
|
||||
lists := map[exectest.ListKey]string{}
|
||||
if tt.installed {
|
||||
lists[exectest.ListKey{Filter: "^foo$", Flags: listFlags}] = installedListOutput
|
||||
}
|
||||
helm := &exectest.Helm{Lists: lists}
|
||||
|
||||
results, errs := st.prepareDiffReleases(helm, []string{}, 1, false, false, false, []string{}, false, false, false, &DiffOpts{
|
||||
SkipDiffValidationOnInstall: tt.skipDiffValidationOnInstall,
|
||||
})
|
||||
|
||||
require.Len(t, errs, 0)
|
||||
require.Len(t, results, 1)
|
||||
|
||||
flags := results[0].flags
|
||||
hasDisableValidation := false
|
||||
for _, f := range flags {
|
||||
if f == "--disable-validation" {
|
||||
hasDisableValidation = true
|
||||
break
|
||||
}
|
||||
}
|
||||
require.Equal(t, tt.wantDisableValidation, hasDisableValidation,
|
||||
"--disable-validation presence mismatch for case %q; flags: %v", tt.name, flags)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareSyncReleases(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user