Add --kubeconfig flag (#1381)

add kubeconfig flag

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
This commit is contained in:
Tim Ramlot
2024-03-01 20:26:54 +08:00
committed by GitHub
parent 7ccacb7ee5
commit 5910ce0b99
8 changed files with 105 additions and 81 deletions
+9 -1
View File
@@ -39,6 +39,7 @@ type execer struct {
version *semver.Version
runner Runner
logger *zap.SugaredLogger
kubeconfig string
kubeContext string
extra []string
decryptedSecretMutex sync.Mutex
@@ -115,7 +116,7 @@ func redactedURL(chart string) string {
}
// New for running helm commands
func New(helmBinary string, options HelmExecOptions, logger *zap.SugaredLogger, kubeContext string, runner Runner) *execer {
func New(helmBinary string, options HelmExecOptions, logger *zap.SugaredLogger, kubeconfig string, kubeContext string, runner Runner) *execer {
// TODO: proper error handling
version, err := GetHelmVersion(helmBinary, runner)
if err != nil {
@@ -132,6 +133,7 @@ func New(helmBinary string, options HelmExecOptions, logger *zap.SugaredLogger,
options: options,
version: version,
logger: logger,
kubeconfig: kubeconfig,
kubeContext: kubeContext,
runner: runner,
decryptedSecrets: make(map[string]*decryptedSecret),
@@ -559,6 +561,9 @@ func (helm *execer) exec(args []string, env map[string]string, overrideEnableLiv
if helm.kubeContext != "" {
cmdargs = append([]string{"--kube-context", helm.kubeContext}, cmdargs...)
}
if helm.kubeconfig != "" {
cmdargs = append([]string{"--kubeconfig", helm.kubeconfig}, cmdargs...)
}
cmd := fmt.Sprintf("exec: %s %s", helm.helmBinary, strings.Join(cmdargs, " "))
helm.logger.Debug(cmd)
enableLiveOutput := helm.options.EnableLiveOutput
@@ -577,6 +582,9 @@ func (helm *execer) execStdIn(args []string, env map[string]string, stdin io.Rea
if helm.kubeContext != "" {
cmdargs = append([]string{"--kube-context", helm.kubeContext}, cmdargs...)
}
if helm.kubeconfig != "" {
cmdargs = append([]string{"--kubeconfig", helm.kubeconfig}, cmdargs...)
}
cmd := fmt.Sprintf("exec: %s %s", helm.helmBinary, strings.Join(cmdargs, " "))
helm.logger.Debug(cmd)
outBytes, err := helm.runner.ExecuteStdIn(helm.helmBinary, cmdargs, env, stdin)