In test framework LoadConfig(), use CurrentContext.Server for TestContext.Host

if it is unset. Otherwise, kubectl exec through http/kubectl proxy tests in
test/e2e/kubectl/kubectl.go would fail with "--host variable must be set to
the full URI to the api server on e2e run" error.
With this change, running the following tests can now pass:
$ e2e.test --kubeconfig=xxx --ginkgo.focus="should support exec through"
This commit is contained in:
Jiaying Zhang 2020-01-09 09:56:51 -08:00
parent 110da204f6
commit 3698a2540d

View File

@ -557,6 +557,14 @@ func LoadConfig() (config *restclient.Config, err error) {
}
return nil, err
}
// In case Host is not set in TestContext, sets it as
// CurrentContext Server for k8s API client to connect to.
if TestContext.Host == "" && c.Clusters != nil {
currentContext, ok := c.Clusters[c.CurrentContext]
if ok {
TestContext.Host = currentContext.Server
}
}
return clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: TestContext.Host}}).ClientConfig()
}