-
Notifications
You must be signed in to change notification settings - Fork 19
/
plugin.go
60 lines (51 loc) · 1.41 KB
/
plugin.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
package k8s
import (
"github.com/Aptomi/aptomi/pkg/config"
"github.com/Aptomi/aptomi/pkg/lang"
"github.com/Aptomi/aptomi/pkg/plugin"
"github.com/Aptomi/aptomi/pkg/util/sync"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// Plugin represents Kubernetes cluster plugin
type Plugin struct {
once sync.Init
config config.K8s
Cluster *lang.Cluster
RestConfig *rest.Config
ClientConfig clientcmd.ClientConfig
ExternalAddress string
}
var _ plugin.ClusterPlugin = &Plugin{}
// New creates new instance of the Kubernetes cluster plugin for specified Cluster and plugins config
func New(cluster *lang.Cluster, cfg config.Plugins) (plugin.ClusterPlugin, error) {
return &Plugin{
config: cfg.K8s,
Cluster: cluster,
}, nil
}
// Validate checks Kubernetes cluster by connecting to it
func (p *Plugin) Validate() error {
err := p.Init()
if err != nil {
return err
}
_, err = p.NewClient()
return err
}
// Init parses Kubernetes cluster config and retrieves external address for Kubernetes cluster
func (p *Plugin) Init() error {
return p.once.Do(func() error {
err := p.parseClusterConfig()
if err != nil {
return err
}
p.ExternalAddress, err = p.getExternalAddress()
return err
})
}
// Cleanup intended to run cleanup operations for plugin, but it's not used in Kubernetes cluster plugin
func (p *Plugin) Cleanup() error {
// no cleanup needed
return nil
}