From 1c59d0a539aad025ee62cf894eb9b6800ed06ebc Mon Sep 17 00:00:00 2001 From: Hubertbits <170125456+hubertbits@users.noreply.github.com> Date: Wed, 16 Apr 2025 15:50:50 +0200 Subject: [PATCH] Integrate include-crd flag for diff and depending commands Signed-off-by: yxxhero --- pkg/app/app.go | 2 ++ pkg/app/versions.go | 18 ++++---------- pkg/state/helmx.go | 25 +++++++++++++++++++ pkg/state/state.go | 60 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index f7f3bedc..db1ee3a5 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -1618,6 +1618,8 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error) Output: c.DiffOutput(), Color: c.Color(), NoColor: c.NoColor(), + SkipCRDs: c.SkipCRDs(), + IncludeCRDs: c.ShouldIncludeCRDs(), Set: c.Set(), DiffArgs: c.DiffArgs(), SkipDiffOnInstall: c.SkipDiffOnInstall(), diff --git a/pkg/app/versions.go b/pkg/app/versions.go index 5943a9d5..ec273dee 100644 --- a/pkg/app/versions.go +++ b/pkg/app/versions.go @@ -1,34 +1,26 @@ package app -const ( - HelmRequiredVersion = "v3.16.4" - HelmRecommendedVersion = "v3.17.3" - HelmDiffRecommendedVersion = "v3.11.0" - HelmSecretsRecommendedVersion = "v4.6.3" - HelmGitRecommendedVersion = "v1.3.0" - HelmS3RecommendedVersion = "v0.16.3" - HelmInstallCommand = "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" -) +import "github.com/helmfile/helmfile/pkg/version" var helmPlugins = []helmRecommendedPlugin{ { name: "diff", - version: HelmDiffRecommendedVersion, + version: version.HelmDiffRecommendedVersion, repo: "https://github.com/databus23/helm-diff", }, { name: "secrets", - version: HelmSecretsRecommendedVersion, + version: version.HelmSecretsRecommendedVersion, repo: "https://github.com/jkroepke/helm-secrets", }, { name: "s3", - version: HelmS3RecommendedVersion, + version: version.HelmS3RecommendedVersion, repo: "https://github.com/hypnoglow/helm-s3.git", }, { name: "helm-git", - version: HelmGitRecommendedVersion, + version: version.HelmGitRecommendedVersion, repo: "https://github.com/aslafy-z/helm-git.git", }, } diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 00d29cac..5d689237 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -229,6 +229,31 @@ func (st *HelmState) appendShowOnlyFlags(flags []string, showOnly []string) []st return flags } +// appendCRDFlags appends the appropriate CRD-related flag to the command line flags +// based on the provided boolean parameters. +// +// If skipCRDs is true, it appends "--skip-crds" to the flags. +// Otherwise, if includeCRDs is true, it appends "--include-crds" to the flags. +// If neither condition is met, it returns the flags unchanged. +// +// This function ensures that skipCRDs takes precedence over includeCRDs when both are true. +// +// Parameters: +// - flags: The existing slice of command line flags +// - skipCRDs: Whether to skip CRDs installation/processing +// - includeCRDs: Whether to include CRDs installation/processing +// +// Returns: +// - The updated slice of command line flags +func (st *HelmState) appendCRDFlags(flags []string, skipCRDs, includeCRDs bool) []string { + if skipCRDs { + return append(flags, "--skip-crds") + } else if includeCRDs { + return append(flags, "--include-crds") + } + return flags +} + type Chartify struct { Opts *chartify.ChartifyOpts Clean func() diff --git a/pkg/state/state.go b/pkg/state/state.go index 03d2be61..9810b96e 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -702,9 +702,7 @@ func (st *HelmState) prepareSyncReleases(helm helmexec.Interface, additionalValu } } - if opts.SkipCRDs { - flags = append(flags, "--skip-crds") - } + flags = st.appendCRDFlags(flags, opts.SkipCRDs, opts.IncludeCRDs) flags = st.appendValuesControlModeFlag(flags, opts.ReuseValues, opts.ResetValues) @@ -794,6 +792,7 @@ type SyncOpts struct { Set []string SkipCleanup bool SkipCRDs bool + IncludeCRDs bool Wait bool WaitRetries int WaitForJobs bool @@ -1497,6 +1496,7 @@ type TemplateOpts struct { Set []string SkipCleanup bool OutputDirTemplate string + SkipCRDs bool IncludeCRDs bool NoHooks bool SkipTests bool @@ -1579,9 +1579,7 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, flags = append(flags, "--validate") } - if opts.IncludeCRDs { - flags = append(flags, "--include-crds") - } + flags = st.appendCRDFlags(flags, opts.SkipCRDs, opts.IncludeCRDs) if opts.NoHooks { flags = append(flags, "--no-hooks") @@ -1854,10 +1852,7 @@ func (st *HelmState) commonDiffFlags(detailedExitCode bool, stripTrailingCR bool } } - // internally we only care about include-crds since skip-crds is misleading and used only in command interface - if opt.IncludeCRDs { - flags = append(flags, "--include-crds") - } + flags = st.appendCRDFlags(flags, opt.SkipCRDs, opt.IncludeCRDs) flags = st.appendExtraDiffFlags(flags, opt) @@ -2036,6 +2031,7 @@ type DiffOpts struct { // If this is true, Color has no effect. NoColor bool Set []string + SkipCRDs bool IncludeCRDs bool SkipCleanup bool SkipDiffOnInstall bool @@ -2752,6 +2748,17 @@ func (st *HelmState) timeoutFlags(release *ReleaseSpec) []string { return flags } +// flagsForUpgrade returns the flags for the helm upgrade command for the given release. +// It considers both global options and release-specific settings to determine the appropriate flags. +// The returned flags include settings for CRDs, values, wait conditions, hooks, timeouts, and other upgrade-specific options. +// +// Parameters: +// - release: The release specification containing release-specific settings +// - workerIndex: The index of the worker processing this release (for concurrent operations) +// - opt: Options containing global settings for the upgrade operation +// +// Returns: +// - A string slice containing all flags to be passed to the helm upgrade command func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSpec, workerIndex int, opt *SyncOpts) ([]string, []string, error) { var flags []string flags = st.appendChartVersionFlags(flags, release) @@ -2845,6 +2852,17 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp return append(flags, common...), clean, nil } +// flagsForTemplate returns the flags for the helm template command for the given release. +// It considers both global options and release-specific settings to determine the appropriate flags. +// The returned flags include settings for CRDs, values, validation, output formatting, and other template-specific options. +// +// Parameters: +// - release: The release specification containing release-specific settings +// - workerIndex: The index of the worker processing this release (for concurrent operations) +// - opt: Options containing global settings for the template operation +// +// Returns: +// - A string slice containing all flags to be passed to the helm template command func (st *HelmState) flagsForTemplate(helm helmexec.Interface, release *ReleaseSpec, workerIndex int, opt *TemplateOpts) ([]string, []string, error) { var flags []string flags = st.appendChartVersionFlags(flags, release) @@ -2876,6 +2894,17 @@ func (st *HelmState) flagsForTemplate(helm helmexec.Interface, release *ReleaseS return append(flags, common...), files, nil } +// flagsForDiff returns the flags for the helm diff command for the given release +// It considers both global options and release-specific settings to determine the appropriate flags. +// The returned flags include settings for CRDs, values, validation, hooks, and other diff-specific options. +// +// Parameters: +// - release: The release specification containing release-specific settings +// - workerIndex: The index of the worker processing this release (for concurrent operations) +// - opt: Options containing global settings for the diff operation +// +// Returns: +// - A string slice containing all flags to be passed to the helm diff command func (st *HelmState) flagsForDiff(helm helmexec.Interface, release *ReleaseSpec, disableValidation bool, workerIndex int, opt *DiffOpts) ([]string, []string, error) { settings := cli.New() var flags []string @@ -3077,6 +3106,17 @@ func (st *HelmState) isDevelopment(release *ReleaseSpec) bool { return result } +// flagsForLint returns the flags for the helm lint command for the given release. +// It considers both global options and release-specific settings to determine the appropriate flags. +// The returned flags include settings for values files, set values, and other lint-specific options. +// +// Parameters: +// - release: The release specification containing release-specific settings +// - workerIndex: The index of the worker processing this release (for concurrent operations) +// - opt: Options containing global settings for the lint operation +// +// Returns: +// - A string slice containing all flags to be passed to the helm lint command func (st *HelmState) flagsForLint(helm helmexec.Interface, release *ReleaseSpec, workerIndex int) ([]string, []string, error) { flags, files, err := st.namespaceAndValuesFlags(helm, release, workerIndex) if err != nil {