minikube upate-cotext: Fix nil pointer dereference

pull/8989/head
Kazuki Suda 2020-08-13 12:19:42 +09:00
parent a3fe0f5c49
commit c41a5f19b7
No known key found for this signature in database
GPG Key ID: F735607417C95F32
3 changed files with 16 additions and 22 deletions

1
go.mod
View File

@ -72,7 +72,6 @@ require (
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
golang.org/x/build v0.0.0-20190927031335-2835ba2e683f
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/sync v0.0.0-20200317015054-43a5402ce75a
golang.org/x/sys v0.0.0-20200523222454-059865788121

View File

@ -21,7 +21,6 @@ import (
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
@ -31,7 +30,6 @@ import (
"k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/tools/clientcmd/api/latest"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
pkgutil "k8s.io/minikube/pkg/util"
"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")
}
address := "https://" + hostname + ":" + strconv.Itoa(port)
// 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")
}
if _, ok := cfg.Clusters[contextName]; !ok {
return false, errors.Errorf("%q does not appear in %s", contextName, confpath)
}
cfg.Clusters[contextName].Server = address
cfg.Clusters[contextName].Server = "https://" + hostname + ":" + strconv.Itoa(port)
err = writeToFile(cfg, confpath)
if err != nil {
return false, errors.Wrap(err, "write")

View File

@ -343,6 +343,18 @@ func TestUpdateIP(t *testing.T) {
if 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)
}
})
}