mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-21 07:56:59 +02:00
feat: add an option to set a custom kustomize binary (#1012)
Signed-off-by: Alessio Dionisi <me@alessiodionisi.com>
This commit is contained in:
+8
-5
@@ -30,6 +30,7 @@ var Cancel goContext.CancelFunc
|
||||
type App struct {
|
||||
OverrideKubeContext string
|
||||
OverrideHelmBinary string
|
||||
OverrideKustomizeBinary string
|
||||
EnableLiveOutput bool
|
||||
StripArgsValuesOnExitError bool
|
||||
DisableForceUpdate bool
|
||||
@@ -74,6 +75,7 @@ func New(conf ConfigProvider) *App {
|
||||
return Init(&App{
|
||||
OverrideKubeContext: conf.KubeContext(),
|
||||
OverrideHelmBinary: conf.HelmBinary(),
|
||||
OverrideKustomizeBinary: conf.KustomizeBinary(),
|
||||
EnableLiveOutput: conf.EnableLiveOutput(),
|
||||
StripArgsValuesOnExitError: conf.StripArgsValuesOnExitError(),
|
||||
DisableForceUpdate: conf.DisableForceUpdate(),
|
||||
@@ -758,11 +760,12 @@ func (a *App) loadDesiredStateFromYaml(file string, opts ...LoadOpts) (*state.He
|
||||
logger: a.Logger,
|
||||
remote: a.remote,
|
||||
|
||||
overrideKubeContext: a.OverrideKubeContext,
|
||||
overrideHelmBinary: a.OverrideHelmBinary,
|
||||
enableLiveOutput: a.EnableLiveOutput,
|
||||
getHelm: a.getHelm,
|
||||
valsRuntime: a.valsRuntime,
|
||||
overrideKubeContext: a.OverrideKubeContext,
|
||||
overrideHelmBinary: a.OverrideHelmBinary,
|
||||
overrideKustomizeBinary: a.OverrideKustomizeBinary,
|
||||
enableLiveOutput: a.EnableLiveOutput,
|
||||
getHelm: a.getHelm,
|
||||
valsRuntime: a.valsRuntime,
|
||||
}
|
||||
|
||||
return ld.Load(file, op)
|
||||
|
||||
@@ -5,6 +5,7 @@ import "go.uber.org/zap"
|
||||
type ConfigProvider interface {
|
||||
Args() string
|
||||
HelmBinary() string
|
||||
KustomizeBinary() string
|
||||
EnableLiveOutput() bool
|
||||
StripArgsValuesOnExitError() bool
|
||||
DisableForceUpdate() bool
|
||||
|
||||
@@ -20,13 +20,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultHelmBinary = state.DefaultHelmBinary
|
||||
DefaultHelmBinary = state.DefaultHelmBinary
|
||||
DefaultKustomizeBinary = state.DefaultKustomizeBinary
|
||||
)
|
||||
|
||||
type desiredStateLoader struct {
|
||||
overrideKubeContext string
|
||||
overrideHelmBinary string
|
||||
enableLiveOutput bool
|
||||
overrideKubeContext string
|
||||
overrideHelmBinary string
|
||||
overrideKustomizeBinary string
|
||||
enableLiveOutput bool
|
||||
|
||||
env string
|
||||
namespace string
|
||||
@@ -152,7 +154,7 @@ func (ld *desiredStateLoader) loadFileWithOverrides(inheritedEnv, overrodeEnv *e
|
||||
}
|
||||
|
||||
func (a *desiredStateLoader) underlying() *state.StateCreator {
|
||||
c := state.NewCreator(a.logger, a.fs, a.valsRuntime, a.getHelm, a.overrideHelmBinary, a.remote, a.enableLiveOutput, a.lockFilePath)
|
||||
c := state.NewCreator(a.logger, a.fs, a.valsRuntime, a.getHelm, a.overrideHelmBinary, a.overrideKustomizeBinary, a.remote, a.enableLiveOutput, a.lockFilePath)
|
||||
c.LoadFile = a.loadFile
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import (
|
||||
|
||||
// GlobalOptions is the global configuration for the Helmfile CLI.
|
||||
type GlobalOptions struct {
|
||||
// helmBinary is the path to the Helm binary.
|
||||
// HelmBinary is the path to the Helm binary.
|
||||
HelmBinary string
|
||||
// KustomizeBinary is the path to the Kustomize binary.
|
||||
KustomizeBinary string
|
||||
// File is the path to the Helmfile.
|
||||
File string
|
||||
// Environment is the name of the environment to use.
|
||||
@@ -93,6 +95,11 @@ func (g *GlobalImpl) HelmBinary() string {
|
||||
return g.GlobalOptions.HelmBinary
|
||||
}
|
||||
|
||||
// KustomizeBinary returns the path to the Kustomize binary.
|
||||
func (g *GlobalImpl) KustomizeBinary() string {
|
||||
return g.GlobalOptions.KustomizeBinary
|
||||
}
|
||||
|
||||
// KubeContext returns the name of the kubectl context to use.
|
||||
func (g *GlobalImpl) KubeContext() string {
|
||||
return g.GlobalOptions.KubeContext
|
||||
|
||||
+15
-4
@@ -18,7 +18,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultHelmBinary = "helm"
|
||||
DefaultHelmBinary = "helm"
|
||||
DefaultKustomizeBinary = "kustomize"
|
||||
)
|
||||
|
||||
type StateLoadError struct {
|
||||
@@ -53,6 +54,8 @@ type StateCreator struct {
|
||||
|
||||
overrideHelmBinary string
|
||||
|
||||
overrideKustomizeBinary string
|
||||
|
||||
enableLiveOutput bool
|
||||
|
||||
remote *remote.Remote
|
||||
@@ -60,7 +63,7 @@ type StateCreator struct {
|
||||
lockFile string
|
||||
}
|
||||
|
||||
func NewCreator(logger *zap.SugaredLogger, fs *filesystem.FileSystem, valsRuntime vals.Evaluator, getHelm func(*HelmState) helmexec.Interface, overrideHelmBinary string, remote *remote.Remote, enableLiveOutput bool, lockFile string) *StateCreator {
|
||||
func NewCreator(logger *zap.SugaredLogger, fs *filesystem.FileSystem, valsRuntime vals.Evaluator, getHelm func(*HelmState) helmexec.Interface, overrideHelmBinary string, overrideKustomizeBinary string, remote *remote.Remote, enableLiveOutput bool, lockFile string) *StateCreator {
|
||||
return &StateCreator{
|
||||
logger: logger,
|
||||
|
||||
@@ -69,8 +72,9 @@ func NewCreator(logger *zap.SugaredLogger, fs *filesystem.FileSystem, valsRuntim
|
||||
valsRuntime: valsRuntime,
|
||||
getHelm: getHelm,
|
||||
|
||||
overrideHelmBinary: overrideHelmBinary,
|
||||
enableLiveOutput: enableLiveOutput,
|
||||
overrideHelmBinary: overrideHelmBinary,
|
||||
overrideKustomizeBinary: overrideKustomizeBinary,
|
||||
enableLiveOutput: enableLiveOutput,
|
||||
|
||||
remote: remote,
|
||||
|
||||
@@ -131,6 +135,13 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState,
|
||||
state.DefaultHelmBinary = DefaultHelmBinary
|
||||
}
|
||||
|
||||
if c.overrideKustomizeBinary != "" && c.overrideKustomizeBinary != DefaultKustomizeBinary {
|
||||
state.DefaultKustomizeBinary = c.overrideKustomizeBinary
|
||||
} else if state.DefaultKustomizeBinary == "" {
|
||||
// Let `helmfile --kustomize-binary ""` not break this helmfile run
|
||||
state.DefaultKustomizeBinary = DefaultKustomizeBinary
|
||||
}
|
||||
|
||||
state.logger = c.logger
|
||||
state.valsRuntime = c.valsRuntime
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func (testEnv stateTestEnv) MustLoadStateWithEnableLiveOutput(t *testing.T, file
|
||||
}
|
||||
|
||||
r := remote.NewRemote(logger, testFs.Cwd, testFs.ToFileSystem())
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", r, enableLiveOutput, "").
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, enableLiveOutput, "").
|
||||
ParseAndLoad([]byte(yamlContent), filepath.Dir(file), file, envName, true, true, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -154,7 +154,7 @@ releaseNamespace: mynamespace
|
||||
env := environment.Environment{
|
||||
Name: "production",
|
||||
}
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", r, false, "").
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, false, "").
|
||||
ParseAndLoad(yamlContent, filepath.Dir(yamlFile), yamlFile, "production", true, true, &env, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -241,7 +241,7 @@ overrideNamespace: myns
|
||||
testFs.Cwd = "/example/path/to"
|
||||
|
||||
r := remote.NewRemote(logger, testFs.Cwd, testFs.ToFileSystem())
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", r, false, "").
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, false, "").
|
||||
ParseAndLoad(yamlContent, filepath.Dir(yamlFile), yamlFile, "production", true, true, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -525,7 +525,7 @@ releaseContext:
|
||||
testFs.Cwd = "/example/path/to"
|
||||
|
||||
r := remote.NewRemote(logger, testFs.Cwd, testFs.ToFileSystem())
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", r, false, "").
|
||||
state, err := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, false, "").
|
||||
ParseAndLoad(yamlContent, filepath.Dir(yamlFile), yamlFile, "production", true, true, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
||||
+3
-1
@@ -43,7 +43,8 @@ const (
|
||||
|
||||
// ReleaseSetSpec is release set spec
|
||||
type ReleaseSetSpec struct {
|
||||
DefaultHelmBinary string `yaml:"helmBinary,omitempty"`
|
||||
DefaultHelmBinary string `yaml:"helmBinary,omitempty"`
|
||||
DefaultKustomizeBinary string `yaml:"kustomizeBinary,omitempty"`
|
||||
|
||||
// DefaultValues is the default values to be overrode by environment values and command-line overrides
|
||||
DefaultValues []any `yaml:"values,omitempty"`
|
||||
@@ -1199,6 +1200,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
|
||||
if chartification != nil && helmfileCommand != "pull" {
|
||||
c := chartify.New(
|
||||
chartify.HelmBin(st.DefaultHelmBinary),
|
||||
chartify.KustomizeBin(st.DefaultKustomizeBinary),
|
||||
chartify.UseHelm3(true),
|
||||
chartify.WithLogf(st.logger.Debugf),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user