Files
helmfile/pkg/testutil/mocks.go
T
Aditya Menon 4f275b3667 feat: add Helm 4 support while maintaining Helm 3 compatibility (#2262)
This commit adds comprehensive support for Helm 4 while maintaining
full backward compatibility with Helm 3. The implementation includes:

- Updated helm version detection to support both Helm 3 and Helm 4
- Added HELMFILE_HELM4 environment variable to control Helm version
- Modified helm execution paths to handle version-specific binaries
- Updated helm plugin installation to support split architecture

- Helm 4: Uses split plugin architecture (3 separate .tgz files)
  - helm-secrets.tgz
  - helm-secrets-getter.tgz
  - helm-secrets-post-renderer.tgz
- Helm 3: Continues using single plugin installation
- Updated Dockerfiles, CI workflows, and core installation code

- Helm 4 requires post-renderers to be plugins, not executable scripts
- Created Helm plugin structure for integration tests
- Updated helmfile.yaml templates to dynamically select renderer type
- Added test plugins: add-cm, add-cm1, add-cm2

- Updated integration tests for Helm 3/4 compatibility
- Created Helm 4 variant expected output files
- Fixed test determinism issues (repo cleanup between iterations)
- Added version-specific output filtering for warnings/messages

- Updated workflows to test both Helm 3 and Helm 4
- Matrix testing across Helm versions
- Updated helm-diff to v3.14.0 for compatibility

- Updated README and docs with Helm 4 information
- Added migration guidance
- Updated version requirements

All changes are backward compatible - existing Helm 3 users will
see no behavior changes.



fix: update Helm 4 lint expected output to match filtered output

The grep filter removes the semver warning, so the expected output
should not include it. Updated lint-helm4 files to match the filtered
output (warning removed, no extra blank line).

Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
2025-11-19 07:49:30 +08:00

169 lines
4.2 KiB
Go

package testutil
import (
"github.com/Masterminds/semver/v3"
chart "helm.sh/helm/v4/pkg/chart/v2"
"github.com/helmfile/helmfile/pkg/helmexec"
)
type noCallHelmExec struct {
}
type HelmExec struct {
*noCallHelmExec
isHelm3 bool
isHelm4 bool
}
func NewHelmExec(isHelm4 bool) *HelmExec {
return &HelmExec{noCallHelmExec: &noCallHelmExec{}, isHelm3: !isHelm4, isHelm4: isHelm4}
}
type VersionHelmExec struct {
*noCallHelmExec
version string
}
func NewVersionHelmExec(version string) *VersionHelmExec {
return &VersionHelmExec{noCallHelmExec: &noCallHelmExec{}, version: version}
}
func (helm *HelmExec) IsHelm3() bool {
return helm.isHelm3
}
func (helm *HelmExec) IsHelm4() bool {
return helm.isHelm4
}
func (helm *VersionHelmExec) IsHelm3() bool {
currentSemVer := semver.MustParse(helm.version)
return currentSemVer.Major() == 3
}
func (helm *VersionHelmExec) IsHelm4() bool {
currentSemVer := semver.MustParse(helm.version)
return currentSemVer.Major() == 4
}
func (helm *VersionHelmExec) IsVersionAtLeast(ver string) bool {
currentSemVer := semver.MustParse(helm.version)
verSemVer := semver.MustParse(ver)
return currentSemVer.Compare(verSemVer) >= 0
}
func (helm *noCallHelmExec) doPanic() {
panic("unexpected call to helm")
}
func (helm *noCallHelmExec) TemplateRelease(name, chart string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) ChartPull(chart string, path string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) ChartExport(chart string, path string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) UpdateDeps(chart string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) BuildDeps(name, chart string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) SetExtraArgs(args ...string) {
helm.doPanic()
}
func (helm *noCallHelmExec) SetHelmBinary(bin string) {
helm.doPanic()
}
func (helm *noCallHelmExec) SetEnableLiveOutput(enableLiveOutput bool) {
helm.doPanic()
}
func (helm *noCallHelmExec) SetDisableForceUpdate(forceUpdate bool) {
helm.doPanic()
}
func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) UpdateRepo() error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) RegistryLogin(name, username, password, caFile, certFile, keyFile string, skipTLSVerify bool) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) SyncRelease(context helmexec.HelmContext, name, chart, namespace string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) DiffRelease(context helmexec.HelmContext, name, chart, namespace string, suppressDiff bool, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) ReleaseStatus(context helmexec.HelmContext, release string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) DeleteRelease(context helmexec.HelmContext, name string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) List(context helmexec.HelmContext, filter string, flags ...string) (string, error) {
helm.doPanic()
return "", nil
}
func (helm *noCallHelmExec) DecryptSecret(context helmexec.HelmContext, name string, flags ...string) (string, error) {
helm.doPanic()
return "", nil
}
func (helm *noCallHelmExec) TestRelease(context helmexec.HelmContext, name string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) Fetch(chart string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) Lint(name, chart string, flags ...string) error {
helm.doPanic()
return nil
}
func (helm *noCallHelmExec) IsHelm3() bool {
helm.doPanic()
return false
}
func (helm *noCallHelmExec) IsHelm4() bool {
helm.doPanic()
return false
}
func (helm *noCallHelmExec) GetVersion() helmexec.Version {
helm.doPanic()
return helmexec.Version{}
}
func (helm *noCallHelmExec) IsVersionAtLeast(versionStr string) bool {
helm.doPanic()
return false
}
func (helm *noCallHelmExec) ShowChart(chartPath string) (chart.Metadata, error) {
helm.doPanic()
return chart.Metadata{}, nil
}