-
Notifications
You must be signed in to change notification settings - Fork 1
/
helm.go
61 lines (49 loc) · 1.49 KB
/
helm.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 k8s
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery"
memory "k8s.io/client-go/discovery/cached"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd"
)
type HelmRESTClientGetter struct {
restConfig *rest.Config
clientConfig clientcmd.ClientConfig
}
func NewRESTClientGetter(restConfig *rest.Config,
clientConfig clientcmd.ClientConfig,
) *HelmRESTClientGetter {
return &HelmRESTClientGetter{
restConfig: restConfig,
clientConfig: clientConfig,
}
}
func (c *HelmRESTClientGetter) ToRESTConfig() (*rest.Config, error) {
return c.restConfig, nil
}
//nolint:ireturn,nolintlint
func (c *HelmRESTClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
config, err := c.ToRESTConfig()
if err != nil {
return nil, err
}
config.Burst = 100
discoveryClient, _ := discovery.NewDiscoveryClientForConfig(config)
return memory.NewMemCacheClient(discoveryClient), nil
}
//nolint:ireturn,nolintlint
func (c *HelmRESTClientGetter) ToRESTMapper() (meta.RESTMapper, error) {
discoveryClient, err := c.ToDiscoveryClient()
if err != nil {
return nil, err
}
mapper := restmapper.NewDeferredDiscoveryRESTMapper(discoveryClient)
//nolint:godox
expander := restmapper.NewShortcutExpander(mapper, discoveryClient, nil) // todo: fix during logger rework
return expander, nil
}
//nolint:ireturn,nolintlint
func (c *HelmRESTClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig {
return c.clientConfig
}