-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
30 lines (27 loc) · 809 Bytes
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package util
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"
"testing"
)
func GetClientSetForTest(t *testing.T) *kubernetes.Clientset {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
overrides := clientcmd.ConfigOverrides{}
clientConfig := clientcmd.NewInteractiveDeferredLoadingClientConfig(loadingRules, &overrides, os.Stdin)
restConfig, err := clientConfig.ClientConfig()
if err != nil {
t.Logf("failed to initclient, %++v", err)
}
if restConfig == nil {
t.Logf("Kube Client is not setup")
return nil
}
// create the clientset
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
t.Errorf("failed to NewForConfig, %++v", err)
}
return clientset
}