-
Notifications
You must be signed in to change notification settings - Fork 93
/
client.go
47 lines (40 loc) 路 1.3 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
package client
import (
"github.com/glasskube/glasskube/api/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
)
type PackageV1Alpha1Client interface {
Packages() PackageInterface
PackageInfos() PackageInfoInterface
WithStores(packageStore cache.Store, packageInfoStore cache.Store) PackageV1Alpha1Client
}
type baseClient struct {
restClient rest.Interface
}
func (c *baseClient) Packages() PackageInterface {
return &packageClient{
restClient: c.restClient,
}
}
func (c *baseClient) PackageInfos() PackageInfoInterface {
return &packageInfoClient{restClient: c.restClient}
}
func (c *baseClient) WithStores(packageStore cache.Store, packageInfoStore cache.Store) PackageV1Alpha1Client {
return &packageCacheClient{PackageV1Alpha1Client: c, packageStore: packageStore, packageInfoStore: packageInfoStore}
}
func New(cfg *rest.Config) (PackageV1Alpha1Client, error) {
pkgRestConfig := *cfg
pkgRestConfig.ContentConfig.GroupVersion = &v1alpha1.GroupVersion
pkgRestConfig.APIPath = "/apis"
pkgRestConfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
restClient, err := rest.RESTClientFor(&pkgRestConfig)
if err != nil {
return nil, err
}
return &baseClient{restClient: restClient}, err
}
func init() {
_ = v1alpha1.AddToScheme(scheme.Scheme)
}