-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
52 lines (43 loc) · 1.19 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
package util
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// ClientInterface .
type ClientInterface interface {
kubernetes.Interface
dynamic.Interface
}
// NewClientSet .
func NewClientSet(contextName string) (cli ClientInterface, err error) {
conf, err := newConfig(contextName)
if err != nil {
return
}
var set clientSet
if set.Clientset, err = kubernetes.NewForConfig(conf); err != nil {
return
}
if set.dynamicClient, err = dynamic.NewForConfig(conf); err != nil {
return
}
return set, err
}
func newConfig(contextName string) (conf *rest.Config, err error) {
configOverrides := &clientcmd.ConfigOverrides{CurrentContext: contextName}
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
return clientcmd.
NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides).
ClientConfig()
}
type clientSet struct {
*kubernetes.Clientset
dynamicClient dynamic.Interface
}
// Resource .
func (c clientSet) Resource(resource schema.GroupVersionResource) dynamic.NamespaceableResourceInterface {
return c.dynamicClient.Resource(resource)
}