mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-27 21:58:50 +00:00
Set kubecontext and kubeconfig for kubectl exec
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
371db07108
commit
c02fbc2794
5 changed files with 19 additions and 11 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue