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"
"math/rand"
"os"
"strings"
"time"
"github.com/rancher/k3s/pkg/server"
@ -17,6 +18,13 @@ import (
func Main() {
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 == "" {
config, err := server.HomeKubeConfig(false, false)
if _, serr := os.Stat(config); err == nil && serr == nil {

Loading…
Cancel
Save