/
localgo.go
75 lines (63 loc) · 2.34 KB
/
localgo.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package local
import (
"github.com/ksctl/ksctl/pkg/resources"
"sigs.k8s.io/kind/pkg/cluster"
"time"
)
type LocalGo interface {
NewProvider(log resources.LoggerFactory, storage resources.StorageFactory, options ...cluster.ProviderOption)
Create(name string, config cluster.CreateOption, image string, wait time.Duration, explictPath func() string) error
Delete(name string, explicitKubeconfigPath string) error
}
type LocalGoClient struct {
provider *cluster.Provider
log resources.LoggerFactory
}
type LocalGoMockClient struct {
log resources.LoggerFactory
store resources.StorageFactory
}
func ProvideMockClient() LocalGo {
return &LocalGoMockClient{}
}
func ProvideClient() LocalGo {
return &LocalGoClient{}
}
func (l *LocalGoClient) NewProvider(log resources.LoggerFactory, _ resources.StorageFactory, options ...cluster.ProviderOption) {
logger := CustomLogger{log}
options = append(options, cluster.ProviderWithLogger(logger))
l.log = log
l.provider = cluster.NewProvider(options...)
}
func (l *LocalGoClient) Create(name string, config cluster.CreateOption, image string, wait time.Duration, explictPath func() string) error {
return l.provider.Create(
name,
config,
cluster.CreateWithNodeImage(image),
cluster.CreateWithWaitForReady(wait),
cluster.CreateWithKubeconfigPath(explictPath()),
cluster.CreateWithDisplayUsage(true),
cluster.CreateWithDisplaySalutation(true),
)
}
func (l *LocalGoClient) Delete(name string, explicitKubeconfigPath string) error {
return l.provider.Delete(name, explicitKubeconfigPath)
}
func (l *LocalGoMockClient) NewProvider(log resources.LoggerFactory, storage resources.StorageFactory, options ...cluster.ProviderOption) {
log.Debug("NewProvider initialized", "options", options)
l.store = storage
l.log = log
}
func (l *LocalGoMockClient) Create(name string, config cluster.CreateOption, image string, wait time.Duration, explictPath func() string) error {
path, err := createNecessaryConfigs(name)
l.log.Debug("Printing", "path", path, "error", err)
l.log.Success("Created the cluster",
"name", name, "config", config,
"image", image, "wait", wait.String(),
"configPath", explictPath())
return nil
}
func (l *LocalGoMockClient) Delete(name string, explicitKubeconfigPath string) error {
l.log.Success("Deleted the cluster", "name", name, "kubeconfigPath", explicitKubeconfigPath)
return nil
}