-
Notifications
You must be signed in to change notification settings - Fork 65
/
client.go
55 lines (47 loc) · 1.38 KB
/
client.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2021 Red Hat, Inc.
// Copyright Contributors to the Open Cluster Management project
package utils
import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
)
func getKubeClient(opt TestOptions, isHub bool) kubernetes.Interface {
clientKube := NewKubeClient(
opt.HubCluster.ClusterServerURL,
opt.KubeConfig,
opt.HubCluster.KubeContext)
if !isHub && len(opt.ManagedClusters) > 0 {
clientKube = NewKubeClient(
opt.ManagedClusters[0].ClusterServerURL,
opt.ManagedClusters[0].KubeConfig,
opt.ManagedClusters[0].KubeContext)
klog.V(1).Infof("New kubeclient for managedcluster <%v>", opt.ManagedClusters[0].Name)
}
return clientKube
}
func GetKubeClientDynamic(opt TestOptions, isHub bool) dynamic.Interface {
url := opt.HubCluster.ClusterServerURL
kubeConfig := opt.KubeConfig
kubeContext := opt.HubCluster.KubeContext
if !isHub && len(opt.ManagedClusters) > 0 {
url = opt.ManagedClusters[0].ClusterServerURL
kubeConfig = opt.ManagedClusters[0].KubeConfig
kubeContext = opt.ManagedClusters[0].KubeContext
}
config, err := LoadConfig(url, kubeConfig, kubeContext)
if err != nil {
panic(err)
}
clientset, err := dynamic.NewForConfig(config)
if err != nil {
panic(err)
}
return clientset
}
func GetManagedClusterName(opt TestOptions) string {
if len(opt.ManagedClusters) > 0 {
return opt.ManagedClusters[0].Name
}
return ""
}