Skip to content

Commit

Permalink
support kubeconfig options when using kubectl command
Browse files Browse the repository at this point in the history
Summary: the px cli has the --kubeconfig option, but the internal
 kubectl command didn't respect it.

Signed-off-by: Xudong Zhang <felixmelon@gmail.com>
  • Loading branch information
zxdvd committed Mar 15, 2023
1 parent c8e5065 commit e58804e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pixie_cli/pkg/utils/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ var (
return nil
})
hasKubectlCheck = NamedCheck(fmt.Sprintf("Kubectl > %s is present", kubectlMinVersion), func() error {
result, err := exec.Command("kubectl", "version", "-o", "yaml").Output()
cmd := k8s.KubectlCmd("version", "-o", "yaml")
result, err := cmd.Output()
if err != nil {
return err
}
Expand Down Expand Up @@ -237,7 +238,8 @@ var (
return nil
})
userCanCreateNamespace = NamedCheck("User can create namespace", func() error {
result, err := exec.Command("kubectl", "auth", "can-i", "create", "namespace").Output()
cmd := k8s.KubectlCmd("auth", "can-i", "create", "namespace")
result, err := cmd.Output()
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/shared/k8s/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
"apply.go",
"auth.go",
"delete.go",
"kubectl.go",
"logs.go",
"secrets.go",
"selector.go",
Expand Down
30 changes: 30 additions & 0 deletions src/utils/shared/k8s/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2018- The Pixie Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package k8s

import "os/exec"

func KubectlCmd(args ...string) *exec.Cmd {
args_ := []string{}
if *kubeconfig != "" {
args_ = append(args_, "--kubeconfig", *kubeconfig)
}
args_ = append(args_, args...)
return exec.Command("kubectl", args_...)
}

0 comments on commit e58804e

Please sign in to comment.