Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support kubeconfig options when using kubectl command #1057

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
support kubeconfig options when using kubectl command
Summary: When deploy using  `px --kubeconfig THE_KUBE_FILE deploy`,
it failed with error `✕    Kubectl > 1.10.0 is present  ERR: exit status 1`.

And I found the px cli has the `--kubeconfig` option, but the internal
kubectl command didn't respect it.

Relevant Issues: N/A

Type of change: /kind bug

Test Plan: Run `px deploy` with `--kubeconfig` option should work without
problem.

Signed-off-by: Xudong Zhang <felixmelon@gmail.com>
  • Loading branch information
zxdvd committed Mar 24, 2023
commit 61f586d6f2e21dd12717c2b9c6b7e8d3df0c7c68
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
32 changes: 32 additions & 0 deletions src/utils/shared/k8s/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 (
"fmt"
"os/exec"
)

func KubectlCmd(args ...string) *exec.Cmd {
cmd := exec.Command("kubectl", args...)
if *kubeconfig != "" {
cmd.Env = append(cmd.Environ(), fmt.Sprintf("KUBECONFIG=%s", *kubeconfig))
}
return cmd
}