Set kubecontext and kubeconfig for kubectl exec

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2020-11-26 11:53:08 +02:00
parent 371db07108
commit c02fbc2794
5 changed files with 19 additions and 11 deletions

View File

@ -60,9 +60,17 @@ const (
ModeCapture ExecMode = "capture.stderr|stdout"
)
func ExecKubectlCommand(ctx context.Context, mode ExecMode, args ...string) (string, error) {
func ExecKubectlCommand(ctx context.Context, mode ExecMode, kubeConfigPath string, kubeContext string, args ...string) (string, error) {
var stdoutBuf, stderrBuf bytes.Buffer
if kubeConfigPath != "" {
args = append(args, "--kubeconfig="+kubeConfigPath)
}
if kubeContext != "" {
args = append(args, "--context="+kubeContext)
}
c := exec.CommandContext(ctx, "kubectl", args...)
if mode == ModeStderrOS {