talos/internal/integration/base/k8s.go
Andrey Smirnov ebd40bd0eb chore: use osctl cluster --wait in basic-integration
There are few workarounds for Drone way of running integration test:
DinD runs as a separate pod, and we can only access its exposed on the
"host" ports, while from Talos cluster this endpoint is not reachable.

So internally Talos nodes still use addresses like "10.5.0.2", while
test is using "docker" to access it (that's name of the `docker` service
in the pipeline).

When running locally, 127.0.0.1 is used as endpoint, which should work
fine both on OS X and Linux.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-12-30 15:15:42 -08:00

51 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build integration_k8s
package base
import (
"context"
"time"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
// K8sSuite is a base suite for K8s tests
type K8sSuite struct {
APISuite
Clientset *kubernetes.Clientset
DiscoveryClient *discovery.DiscoveryClient
}
// SetupSuite initializes Kubernetes client
func (k8sSuite *K8sSuite) SetupSuite() {
k8sSuite.APISuite.SetupSuite()
kubeconfig, err := k8sSuite.Client.Kubeconfig(context.Background())
k8sSuite.Require().NoError(err)
config, err := clientcmd.BuildConfigFromKubeconfigGetter("", func() (*clientcmdapi.Config, error) {
return clientcmd.Load(kubeconfig)
})
k8sSuite.Require().NoError(err)
// patch timeout
config.Timeout = time.Minute
if k8sSuite.K8sEndpoint != "" {
config.Host = k8sSuite.K8sEndpoint
}
k8sSuite.Clientset, err = kubernetes.NewForConfig(config)
k8sSuite.Require().NoError(err)
k8sSuite.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(config)
k8sSuite.Require().NoError(err)
}