Browse Source

Check for `--kubeconfig` flag with embedded `kubectl` (#5064)

* Check for kubeconfig flag

Signed-off-by: Derek Nola <derek.nola@suse.com>
pull/5069/head
Derek Nola 3 years ago committed by GitHub
parent
commit
4f36c82ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      pkg/kubectl/main.go

8
pkg/kubectl/main.go

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
"strings"
"time" "time"
"github.com/rancher/k3s/pkg/server" "github.com/rancher/k3s/pkg/server"
@ -17,6 +18,13 @@ import (
func Main() { func Main() {
kubenv := os.Getenv("KUBECONFIG") kubenv := os.Getenv("KUBECONFIG")
for i, arg := range os.Args {
if strings.HasPrefix(arg, "--kubeconfig=") {
kubenv = strings.Split(arg, "=")[1]
} else if strings.HasPrefix(arg, "--kubeconfig") && i+1 < len(os.Args) {
kubenv = os.Args[i+1]
}
}
if kubenv == "" { if kubenv == "" {
config, err := server.HomeKubeConfig(false, false) config, err := server.HomeKubeConfig(false, false)
if _, serr := os.Stat(config); err == nil && serr == nil { if _, serr := os.Stat(config); err == nil && serr == nil {

Loading…
Cancel
Save