* Rename VK to chewong for development purpose * Rename basic_test.go to basic.go * Add e2e.go and suite.go * Disable tests in node.go * End to end tests are now importable as a testing suite * Remove 'test' from test files * Add documentations * Rename chewong back to virtual-kubelet * Change 'Testing Suite' to 'Test Suite' * Add the ability to skip certain testss * Add unit tests for suite.go * Add README.md for importable e2e test suite * VK implementation has to be based on VK v1.0.0 * Stricter checks on validating test functions * Move certain files back to internal folder * Add WatchTimeout as a config field * Add slight modifications
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package framework
|
|
|
|
import (
|
|
"time"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
)
|
|
|
|
// Framework encapsulates the configuration for the current run, and provides helper methods to be used during testing.
|
|
type Framework struct {
|
|
KubeClient kubernetes.Interface
|
|
Namespace string
|
|
NodeName string
|
|
WatchTimeout time.Duration
|
|
}
|
|
|
|
// NewTestingFramework returns a new instance of the testing framework.
|
|
func NewTestingFramework(kubeconfig, namespace, nodeName string, watchTimeout time.Duration) *Framework {
|
|
return &Framework{
|
|
KubeClient: createKubeClient(kubeconfig),
|
|
Namespace: namespace,
|
|
NodeName: nodeName,
|
|
WatchTimeout: watchTimeout,
|
|
}
|
|
}
|
|
|
|
// createKubeClient creates a new Kubernetes client based on the specified kubeconfig file.
|
|
// If no value for kubeconfig is specified, in-cluster configuration is assumed.
|
|
func createKubeClient(kubeconfig string) *kubernetes.Clientset {
|
|
var (
|
|
cfg *rest.Config
|
|
err error
|
|
)
|
|
if kubeconfig == "" {
|
|
cfg, err = rest.InClusterConfig()
|
|
} else {
|
|
cfg, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
|
|
}
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return kubernetes.NewForConfigOrDie(cfg)
|
|
}
|