/
client.go
45 lines (39 loc) · 1.03 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
package chClient
import (
"github.com/containerum/chkit/pkg/chkitErrors"
"github.com/containerum/chkit/pkg/model"
kubeClient "github.com/containerum/kube-client/pkg/client"
)
const (
// ErrUnableToInitClient -- unable to init client
ErrUnableToInitClient chkitErrors.Err = "unable to init client"
)
// Client -- chkit core client
type Client struct {
model.Config
factory KubeAPIclientSetup
isInitialized bool
kubeAPIClient kubeClient.Client
}
func (client *Client) IsInitialized() bool {
return client.isInitialized
}
func (client *Client) Init(setup KubeAPIclientSetup) error {
if setup == nil {
setup = WithCommonAPI
}
kcli, err := setup(client.Config)
if err != nil {
return ErrUnableToInitClient.Wrap(err)
}
client.kubeAPIClient = *kcli
client.isInitialized = true
client.factory = setup
return nil
}
func (client *Client) ReInit() error {
if client.factory == nil || !client.isInitialized {
panic("[chkit/pkg/client.Client.ReInit] try to reinit not initialized client")
}
return client.Init(client.factory)
}