Skip to content

Commit

Permalink
Fix bug: [karmadactl init] can not read KUBECONFIG environment variable
Browse files Browse the repository at this point in the history
Signed-off-by: lonelyCZ <531187475@qq.com>
  • Loading branch information
lonelyCZ committed Mar 7, 2022
1 parent b33bda9 commit c452a6e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/karmadactl/cmdinit/kubernetes/deploy.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"os"
"path"
"strings"
"time"
Expand Down Expand Up @@ -70,10 +71,6 @@ type CommandInitOption struct {

// Validate Check that there are enough flags to run the command.
func (i *CommandInitOption) Validate(parentCommand string) error {
if !utils.PathIsExist(i.KubeConfig) {
return fmt.Errorf("kubeconfig file does not exist.absolute path to the kubeconfig file")
}

if i.EtcdStorageMode == "hostPath" && i.EtcdHostDataPath == "" {
return fmt.Errorf("when etcd storage mode is hostPath, dataPath is not empty. See '%s init --help'", parentCommand)
}
Expand All @@ -95,6 +92,16 @@ func (i *CommandInitOption) Validate(parentCommand string) error {

// Complete Initialize k8s client
func (i *CommandInitOption) Complete() error {
// check config path of host kubernetes cluster
env := os.Getenv("KUBECONFIG")
if env != "" {
i.KubeConfig = env
}

if !utils.PathIsExist(i.KubeConfig) {
return fmt.Errorf("kubeconfig file does not exist.absolute path to the kubeconfig file")
}

restConfig, err := utils.RestConfig(i.KubeConfig)
if err != nil {
return err
Expand Down

0 comments on commit c452a6e

Please sign in to comment.