mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-20 13:17:17 +02:00
feat: show live output from the Helm binary (#286)
* feat: show live output from the Helm binary Signed-off-by: Rodrigo Fior Kuntzer <rodrigo@miro.com> * fixup! Merge branch 'main' into enable-live-output Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
+11
-1
@@ -28,6 +28,7 @@ import (
|
||||
type App struct {
|
||||
OverrideKubeContext string
|
||||
OverrideHelmBinary string
|
||||
EnableLiveOutput bool
|
||||
|
||||
Logger *zap.SugaredLogger
|
||||
Env string
|
||||
@@ -64,6 +65,7 @@ func New(conf ConfigProvider) *App {
|
||||
return Init(&App{
|
||||
OverrideKubeContext: conf.KubeContext(),
|
||||
OverrideHelmBinary: conf.HelmBinary(),
|
||||
EnableLiveOutput: conf.EnableLiveOutput(),
|
||||
Logger: conf.Logger(),
|
||||
Env: conf.Env(),
|
||||
Namespace: conf.Namespace(),
|
||||
@@ -84,6 +86,10 @@ func Init(app *App) *App {
|
||||
panic(fmt.Sprintf("Failed to initialize vals runtime: %v", err))
|
||||
}
|
||||
|
||||
if app.EnableLiveOutput {
|
||||
app.Logger.Info("Live output is enabled")
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -213,6 +219,9 @@ func (a *App) Template(c TemplateConfigProvider) error {
|
||||
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
|
||||
includeCRDs := c.IncludeCRDs()
|
||||
|
||||
// Live output should never be enabled for the "template" subcommand to avoid breaking `helmfile template | kubectl apply -f -`
|
||||
run.helm.SetEnableLiveOutput(false)
|
||||
|
||||
// `helm template` in helm v2 does not support local chart.
|
||||
// So, we set forceDownload=true for helm v2 only
|
||||
prepErr := run.withPreparedCharts("template", state.ChartPrepareOptions{
|
||||
@@ -717,6 +726,7 @@ func (a *App) loadDesiredStateFromYaml(file string, opts ...LoadOpts) (*state.He
|
||||
|
||||
overrideKubeContext: a.OverrideKubeContext,
|
||||
overrideHelmBinary: a.OverrideHelmBinary,
|
||||
enableLiveOutput: a.EnableLiveOutput,
|
||||
getHelm: a.getHelm,
|
||||
valsRuntime: a.valsRuntime,
|
||||
}
|
||||
@@ -755,7 +765,7 @@ func (a *App) getHelm(st *state.HelmState) helmexec.Interface {
|
||||
key := createHelmKey(bin, kubectx)
|
||||
|
||||
if _, ok := a.helms[key]; !ok {
|
||||
a.helms[key] = helmexec.New(bin, a.Logger, kubectx, &helmexec.ShellRunner{
|
||||
a.helms[key] = helmexec.New(bin, a.EnableLiveOutput, a.Logger, kubectx, &helmexec.ShellRunner{
|
||||
Logger: a.Logger,
|
||||
})
|
||||
}
|
||||
|
||||
+4
-2
@@ -2488,12 +2488,12 @@ func (mock *mockRunner) ExecuteStdIn(cmd string, args []string, env map[string]s
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
func (mock *mockRunner) Execute(cmd string, args []string, env map[string]string) ([]byte, error) {
|
||||
func (mock *mockRunner) Execute(cmd string, args []string, env map[string]string, enableLiveOutput bool) ([]byte, error) {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
func MockExecer(logger *zap.SugaredLogger, kubeContext string) helmexec.Interface {
|
||||
execer := helmexec.New("helm", logger, kubeContext, &mockRunner{})
|
||||
execer := helmexec.New("helm", false, logger, kubeContext, &mockRunner{})
|
||||
return execer
|
||||
}
|
||||
|
||||
@@ -2538,6 +2538,8 @@ func (helm *mockHelmExec) SetExtraArgs(args ...string) {
|
||||
}
|
||||
func (helm *mockHelmExec) SetHelmBinary(bin string) {
|
||||
}
|
||||
func (helm *mockHelmExec) SetEnableLiveOutput(enableLiveOutput bool) {
|
||||
}
|
||||
func (helm *mockHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
|
||||
helm.repos = append(helm.repos, mockRepo{Name: name})
|
||||
return nil
|
||||
|
||||
@@ -5,6 +5,7 @@ import "go.uber.org/zap"
|
||||
type ConfigProvider interface {
|
||||
Args() string
|
||||
HelmBinary() string
|
||||
EnableLiveOutput() bool
|
||||
|
||||
FileOrDir() string
|
||||
KubeContext() string
|
||||
|
||||
@@ -24,6 +24,7 @@ const (
|
||||
type desiredStateLoader struct {
|
||||
overrideKubeContext string
|
||||
overrideHelmBinary string
|
||||
enableLiveOutput bool
|
||||
|
||||
env string
|
||||
namespace string
|
||||
@@ -162,7 +163,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)
|
||||
c := state.NewCreator(a.logger, a.fs, a.valsRuntime, a.getHelm, a.overrideHelmBinary, a.remote, a.enableLiveOutput)
|
||||
c.LoadFile = a.loadFile
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ func (helm *noCallHelmExec) SetExtraArgs(args ...string) {
|
||||
func (helm *noCallHelmExec) SetHelmBinary(bin string) {
|
||||
helm.doPanic()
|
||||
}
|
||||
func (helm *noCallHelmExec) SetEnableLiveOutput(enableLiveOutput bool) {
|
||||
helm.doPanic()
|
||||
}
|
||||
func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify string) error {
|
||||
helm.doPanic()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user