mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-28 23:14:48 +08:00
Set kubecontext and kubeconfig for kubectl exec
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user