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

* Check for kubeconfig flag

Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Derek Nola 2022-02-03 09:00:24 -08:00 committed by GitHub
parent df4147cd57
commit 4f36c82ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {