minikube upate-cotext: Fix nil pointer dereference
parent
a3fe0f5c49
commit
c41a5f19b7
1
go.mod
1
go.mod
|
@ -72,7 +72,6 @@ require (
|
||||||
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
|
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
|
||||||
golang.org/x/build v0.0.0-20190927031335-2835ba2e683f
|
golang.org/x/build v0.0.0-20190927031335-2835ba2e683f
|
||||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
|
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
|
||||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
|
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
|
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
|
||||||
golang.org/x/sys v0.0.0-20200523222454-059865788121
|
golang.org/x/sys v0.0.0-20200523222454-059865788121
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -31,7 +30,6 @@ import (
|
||||||
"k8s.io/client-go/tools/clientcmd/api"
|
"k8s.io/client-go/tools/clientcmd/api"
|
||||||
"k8s.io/client-go/tools/clientcmd/api/latest"
|
"k8s.io/client-go/tools/clientcmd/api/latest"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
"k8s.io/minikube/pkg/minikube/localpath"
|
|
||||||
pkgutil "k8s.io/minikube/pkg/util"
|
pkgutil "k8s.io/minikube/pkg/util"
|
||||||
"k8s.io/minikube/pkg/util/lock"
|
"k8s.io/minikube/pkg/util/lock"
|
||||||
)
|
)
|
||||||
|
@ -121,26 +119,11 @@ func UpdateEndpoint(contextName string, hostname string, port int, confpath stri
|
||||||
return false, errors.Wrap(err, "read")
|
return false, errors.Wrap(err, "read")
|
||||||
}
|
}
|
||||||
|
|
||||||
address := "https://" + hostname + ":" + strconv.Itoa(port)
|
if _, ok := cfg.Clusters[contextName]; !ok {
|
||||||
|
return false, errors.Errorf("%q does not appear in %s", contextName, confpath)
|
||||||
// if the kubeconfig is missed, create new one
|
|
||||||
if len(cfg.Clusters) == 0 {
|
|
||||||
lp := localpath.Profile(contextName)
|
|
||||||
gp := localpath.MiniPath()
|
|
||||||
kcs := &Settings{
|
|
||||||
ClusterName: contextName,
|
|
||||||
ClusterServerAddress: address,
|
|
||||||
ClientCertificate: path.Join(lp, "client.crt"),
|
|
||||||
ClientKey: path.Join(lp, "client.key"),
|
|
||||||
CertificateAuthority: path.Join(gp, "ca.crt"),
|
|
||||||
KeepContext: false,
|
|
||||||
}
|
|
||||||
err = PopulateFromSettings(kcs, cfg)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "populating kubeconfig")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cfg.Clusters[contextName].Server = address
|
|
||||||
|
cfg.Clusters[contextName].Server = "https://" + hostname + ":" + strconv.Itoa(port)
|
||||||
err = writeToFile(cfg, confpath)
|
err = writeToFile(cfg, confpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "write")
|
return false, errors.Wrap(err, "write")
|
||||||
|
|
|
@ -343,6 +343,18 @@ func TestUpdateIP(t *testing.T) {
|
||||||
if test.status != statusActual {
|
if test.status != statusActual {
|
||||||
t.Errorf("Expected status %t, but got %t", test.status, statusActual)
|
t.Errorf("Expected status %t, but got %t", test.status, statusActual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual, err := readOrNew(configFilename)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
expected, err := decode(test.expCfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !configEquals(actual, expected) {
|
||||||
|
t.Errorf("Expected cfg %v, but got %v", expected, actual)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue