-
Notifications
You must be signed in to change notification settings - Fork 27
/
helm.go
56 lines (47 loc) · 1.29 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
package helm
import (
log "github.com/sirupsen/logrus"
"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/helm/client"
"github.com/flant/addon-operator/pkg/helm/helm3"
"github.com/flant/addon-operator/pkg/helm/helm3lib"
)
type ClientFactory struct {
NewClientFn func(logLabels ...map[string]string) client.HelmClient
}
func (f *ClientFactory) NewClient(logLabels ...map[string]string) client.HelmClient {
if f.NewClientFn != nil {
return f.NewClientFn(logLabels...)
}
return nil
}
func InitHelmClientFactory() (*ClientFactory, error) {
helmVersion, err := DetectHelmVersion()
if err != nil {
return nil, err
}
factory := new(ClientFactory)
switch helmVersion {
case Helm3Lib:
log.Info("Helm3Lib detected. Use builtin Helm.")
factory.NewClientFn = helm3lib.NewClient
err = helm3lib.Init(&helm3lib.Options{
Namespace: app.Namespace,
HistoryMax: app.Helm3HistoryMax,
Timeout: app.Helm3Timeout,
})
case Helm3:
log.Infof("Helm 3 detected (path is '%s')", helm3.Helm3Path)
// Use helm3 client.
factory.NewClientFn = helm3.NewClient
err = helm3.Init(&helm3.Helm3Options{
Namespace: app.Namespace,
HistoryMax: app.Helm3HistoryMax,
Timeout: app.Helm3Timeout,
})
}
if err != nil {
return nil, err
}
return factory, nil
}