提交 a15201b1 编写于 作者: M Medya Gh

remove exit from kubeconfig update lib

上级 733ba21a
......@@ -307,7 +307,10 @@ func runStart(cmd *cobra.Command, args []string) {
bs := setupKubeAdm(machineAPI, config.KubernetesConfig)
// The kube config must be update must come before bootstrapping, otherwise health checks may use a stale IP
kubeconfig := setupKubeconfig(host, &config)
kubeconfig, err := setupKubeconfig(host, &config)
if err != nil {
exit.WithError("Failed to setup kubeconfig", err)
}
// pull images or restart cluster
bootstrapCluster(bs, cr, mRunner, config.KubernetesConfig, preExists, isUpgrade)
......@@ -326,12 +329,12 @@ func runStart(cmd *cobra.Command, args []string) {
}
func setupKubeconfig(host *host.Host, config *cfg.Config) *kubeconfig.Setup {
func setupKubeconfig(host *host.Host, config *cfg.Config) (*kubeconfig.Setup, error) {
addr, err := host.Driver.GetURL()
if err != nil {
exit.WithError("Failed to get host URL", err)
}
return kubeconfig.Update(addr, config)
return kubeconfig.Setup(addr, config)
}
func handleDownloadOnly(cacheGroup *errgroup.Group, k8sVersion string) {
......
......@@ -97,7 +97,7 @@ users:
`)
func Test_update(t *testing.T) {
setupCfg := &Setup{
setupCfg := &KCS{
ClusterName: "test",
ClusterServerAddress: "192.168.1.1:8080",
ClientCertificate: "/home/apiserver.crt",
......@@ -108,7 +108,7 @@ func Test_update(t *testing.T) {
var tests = []struct {
description string
cfg *Setup
cfg *KCS
existingCfg []byte
expected api.Config
err bool
......@@ -128,7 +128,7 @@ func Test_update(t *testing.T) {
},
{
description: "keep context",
cfg: &Setup{
cfg: &KCS{
ClusterName: "test",
ClusterServerAddress: "192.168.1.1:8080",
ClientCertificate: "/home/apiserver.crt",
......
......@@ -23,8 +23,8 @@ import (
"k8s.io/client-go/tools/clientcmd/api"
)
// Setup is the kubeconfig setup
type Setup struct {
// KCS is the kubeconfig setup
type KCS struct {
// The name of the cluster for this context
ClusterName string
......@@ -52,17 +52,17 @@ type Setup struct {
}
// SetKubeConfigFile sets the kubeconfig file
func (k *Setup) setPath(kubeConfigFile string) {
func (k *KCS) setPath(kubeConfigFile string) {
k.kubeConfigFile.Store(kubeConfigFile)
}
// fileContent gets the kubeconfig file
func (k *Setup) fileContent() string {
func (k *KCS) fileContent() string {
return k.kubeConfigFile.Load().(string)
}
// Populate populates an api.Config object with values from *Setup
func Populate(cfg *Setup, apiCfg *api.Config) error {
func Populate(cfg *KCS, apiCfg *api.Config) error {
var err error
clusterName := cfg.ClusterName
cluster := api.NewCluster()
......
......@@ -34,19 +34,18 @@ import (
"k8s.io/client-go/tools/clientcmd/api/latest"
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
pkgutil "k8s.io/minikube/pkg/util"
)
// Update sets up kubeconfig to be used by kubectl
func Update(clusterURL string, c *cfg.Config) *Setup {
// Setup sets up kubeconfig to be used by kubectl
func Setup(clusterURL string, c *cfg.Config) (*KCS, error) {
clusterURL = strings.Replace(clusterURL, "tcp://", "https://", -1)
clusterURL = strings.Replace(clusterURL, ":2376", ":"+strconv.Itoa(c.KubernetesConfig.NodePort), -1)
if c.KubernetesConfig.APIServerName != constants.APIServerName {
clusterURL = strings.Replace(clusterURL, c.KubernetesConfig.NodeIP, c.KubernetesConfig.APIServerName, -1)
}
kcs := &Setup{
kcs := &KCS{
ClusterName: cfg.GetMachineName(),
ClusterServerAddress: clusterURL,
ClientCertificate: constants.MakeMiniPath("client.crt"),
......@@ -57,15 +56,16 @@ func Update(clusterURL string, c *cfg.Config) *Setup {
}
kcs.setPath(Path())
if err := update(kcs); err != nil {
exit.WithError("Failed to setup kubeconfig", err)
return kcs, fmt.Errorf("error update kubeconfig: %v", err)
}
return kcs
return kcs, nil
}
// update reads config from disk, adds the minikube settings, and writes it back.
// activeContext is true when minikube is the CurrentContext
// If no CurrentContext is set, the given name will be used.
func update(cfg *Setup) error {
func update(cfg *KCS) error {
glog.Infoln("Using kubeconfig: ", cfg.fileContent())
// read existing config or create new if does not exist
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册