-
Notifications
You must be signed in to change notification settings - Fork 35
/
client.go
61 lines (58 loc) · 2.04 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
56
57
58
59
60
61
package client
import (
harvnetworkclient "github.com/harvester/harvester-network-controller/pkg/generated/clientset/versioned"
harvclient "github.com/harvester/harvester/pkg/generated/clientset/versioned"
"github.com/harvester/harvester/pkg/generated/clientset/versioned/scheme"
"github.com/rancher/wrangler/pkg/kubeconfig"
kubeschema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
storageclient "k8s.io/client-go/kubernetes/typed/storage/v1"
"k8s.io/client-go/rest"
)
type Client struct {
RestConfig *rest.Config
KubeVirtSubresourceClient *rest.RESTClient
KubeClient *kubernetes.Clientset
StorageClassClient *storageclient.StorageV1Client
HarvesterClient *harvclient.Clientset
HarvesterNetworkClient *harvnetworkclient.Clientset
}
func NewClient(kubeConfig, kubeContext string) (*Client, error) {
clientConfig := kubeconfig.GetNonInteractiveClientConfigWithContext(kubeConfig, kubeContext)
restConfig, err := clientConfig.ClientConfig()
if err != nil {
return nil, err
}
copyConfig := rest.CopyConfig(restConfig)
copyConfig.GroupVersion = &kubeschema.GroupVersion{Group: "subresources.kubevirt.io", Version: "v1"}
copyConfig.APIPath = "/apis"
copyConfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
restClient, err := rest.RESTClientFor(copyConfig)
if err != nil {
return nil, err
}
kubeClient, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return nil, err
}
storageClassClient, err := storageclient.NewForConfig(restConfig)
if err != nil {
return nil, err
}
harvClient, err := harvclient.NewForConfig(restConfig)
if err != nil {
return nil, err
}
harvNetworkClient, err := harvnetworkclient.NewForConfig(restConfig)
if err != nil {
return nil, err
}
return &Client{
RestConfig: restConfig,
KubeVirtSubresourceClient: restClient,
KubeClient: kubeClient,
StorageClassClient: storageClassClient,
HarvesterClient: harvClient,
HarvesterNetworkClient: harvNetworkClient,
}, nil
}