Add version package to allow test imports

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
Hubertbits 2025-04-16 10:33:49 +02:00 committed by yxxhero
parent 36db5c374d
commit 8067504097
3 changed files with 56 additions and 6 deletions

View File

@ -14,13 +14,14 @@ import (
"helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/cli"
"github.com/helmfile/helmfile/pkg/helmexec" "github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/version"
) )
var ( var (
manuallyInstallCode = 1 manuallyInstallCode = 1
windowPackageManagers = map[string]string{ windowPackageManagers = map[string]string{
"scoop": fmt.Sprintf("scoop install helm@%s", strings.TrimLeft(HelmRecommendedVersion, "v")), "scoop": fmt.Sprintf("scoop install helm@%s", strings.TrimLeft(version.HelmRecommendedVersion, "v")),
"choco": fmt.Sprintf("choco install kubernetes-helm --version %s", strings.TrimLeft(HelmRecommendedVersion, "v")), "choco": fmt.Sprintf("choco install kubernetes-helm --version %s", strings.TrimLeft(version.HelmRecommendedVersion, "v")),
} }
) )
@ -90,7 +91,7 @@ func (h *HelmfileInit) InstallHelm() error {
return h.installHelmOnWindows() return h.installHelmOnWindows()
} }
err := h.WhetherContinue(fmt.Sprintf("use: '%s'", HelmInstallCommand)) err := h.WhetherContinue(fmt.Sprintf("use: '%s'", version.HelmInstallCommand))
if err != nil { if err != nil {
return err return err
} }
@ -102,14 +103,14 @@ func (h *HelmfileInit) InstallHelm() error {
if err != nil { if err != nil {
return err return err
} }
err = downloadfile(getHelmScript.Name(), HelmInstallCommand) err = downloadfile(getHelmScript.Name(), version.HelmInstallCommand)
if err != nil { if err != nil {
return err return err
} }
_, err = h.runner.Execute("bash", []string{ _, err = h.runner.Execute("bash", []string{
getHelmScript.Name(), getHelmScript.Name(),
"--version", "--version",
HelmRecommendedVersion, version.HelmRecommendedVersion,
}, nil, true) }, nil, true)
if err != nil { if err != nil {
return err return err
@ -182,7 +183,7 @@ func (h *HelmfileInit) CheckHelm() error {
if err != nil { if err != nil {
return err return err
} }
requiredHelmVersion, _ := semver.NewVersion(HelmRequiredVersion) requiredHelmVersion, _ := semver.NewVersion(version.HelmRequiredVersion)
if helmversion.LessThan(requiredHelmVersion) { if helmversion.LessThan(requiredHelmVersion) {
h.logger.Infof("helm version is too low, the current version is %s, the required version is %s", helmversion, requiredHelmVersion) h.logger.Infof("helm version is too low, the current version is %s, the required version is %s", helmversion, requiredHelmVersion)
err = h.UpdateHelm() err = h.UpdateHelm()

38
pkg/version/README.md Normal file
View File

@ -0,0 +1,38 @@
# Version Package
## Overview
The `version` package contains version-related constants and utilities used throughout the Helmfile codebase. It was created as a standalone package to avoid import cycles while making version information accessible to all components.
## Contents
This package includes:
- `HelmRequiredVersion`: The minimum required Helm version for Helmfile
- Other version-related constants and utilities
## Usage
Import this package when you need access to version information:
```go
import "github.com/helmfile/helmfile/pkg/version"
func someFunction() {
// Use version constants
requiredVersion := version.HelmRequiredVersion
// Example usage
fmt.Printf("Helmfile requires Helm version %s or later\n", requiredVersion)
}
```
## Design Considerations
This package is intentionally isolated from other Helmfile packages to prevent import cycles. It should:
- Contain only version-related constants and simple utilities
- Not import other Helmfile packages
- Be kept minimal to serve its specific purpose
When adding new version-related functionality, ensure it belongs here rather than in a more specific package.

11
pkg/version/versions.go Normal file
View File

@ -0,0 +1,11 @@
package version
const (
HelmRequiredVersion = "v3.16.4"
HelmRecommendedVersion = "v3.17.2"
HelmDiffRecommendedVersion = "v3.11.0"
HelmSecretsRecommendedVersion = "v4.6.0"
HelmGitRecommendedVersion = "v0.15.1"
HelmS3RecommendedVersion = "v0.16.0"
HelmInstallCommand = "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
)