19
19
package charts
20
20
21
21
import (
22
- "context"
23
22
"os"
24
23
"path/filepath"
25
24
"strings"
@@ -34,40 +33,20 @@ import (
34
33
helmenv "helm.sh/helm/v3/pkg/cli"
35
34
)
36
35
37
- // API defines management methods for helm charts
38
- type API interface {
39
- GetDefaultEnv () * helmenv.EnvSettings
40
- Connect (ctx context.Context ) error
41
- GenerateChart (project * types.Project , dirname string ) error
42
- GetChartInMemory (project * types.Project ) (* chart.Chart , error )
43
- SaveChart (project * types.Project , dest string ) error
44
-
45
- Install (project * types.Project ) error
46
- Uninstall (projectName string ) error
47
- List (projectName string ) ([]compose.Stack , error )
48
- }
49
-
50
- type sdk struct {
36
+ type SDK struct {
51
37
h * helm.HelmActions
52
38
environment map [string ]string
53
39
}
54
40
55
- // sdk implement API
56
- var _ API = sdk {}
57
-
58
- func NewSDK (ctx store.KubeContext ) (sdk , error ) {
59
- return sdk {
41
+ func NewSDK (ctx store.KubeContext ) (SDK , error ) {
42
+ return SDK {
60
43
environment : environment (),
61
44
h : helm .NewHelmActions (nil ),
62
45
}, nil
63
46
}
64
47
65
- func (s sdk ) Connect (ctx context.Context ) error {
66
- return nil
67
- }
68
-
69
48
// Install deploys a Compose stack
70
- func (s sdk ) Install (project * types.Project ) error {
49
+ func (s SDK ) Install (project * types.Project ) error {
71
50
chart , err := s .GetChartInMemory (project )
72
51
if err != nil {
73
52
return err
@@ -76,21 +55,21 @@ func (s sdk) Install(project *types.Project) error {
76
55
}
77
56
78
57
// Uninstall removes a runnign compose stack
79
- func (s sdk ) Uninstall (projectName string ) error {
58
+ func (s SDK ) Uninstall (projectName string ) error {
80
59
return s .h .Uninstall (projectName )
81
60
}
82
61
83
62
// List returns a list of compose stacks
84
- func (s sdk ) List (projectName string ) ([]compose.Stack , error ) {
63
+ func (s SDK ) List (projectName string ) ([]compose.Stack , error ) {
85
64
return s .h .ListReleases ()
86
65
}
87
66
88
67
// GetDefault initializes Helm EnvSettings
89
- func (s sdk ) GetDefaultEnv () * helmenv.EnvSettings {
68
+ func (s SDK ) GetDefaultEnv () * helmenv.EnvSettings {
90
69
return helmenv .New ()
91
70
}
92
71
93
- func (s sdk ) GetChartInMemory (project * types.Project ) (* chart.Chart , error ) {
72
+ func (s SDK ) GetChartInMemory (project * types.Project ) (* chart.Chart , error ) {
94
73
// replace _ with - in volume names
95
74
for k , v := range project .Volumes {
96
75
volumeName := strings .ReplaceAll (k , "_" , "-" )
@@ -107,15 +86,15 @@ func (s sdk) GetChartInMemory(project *types.Project) (*chart.Chart, error) {
107
86
return helm .ConvertToChart (project .Name , objects )
108
87
}
109
88
110
- func (s sdk ) SaveChart (project * types.Project , dest string ) error {
89
+ func (s SDK ) SaveChart (project * types.Project , dest string ) error {
111
90
chart , err := s .GetChartInMemory (project )
112
91
if err != nil {
113
92
return err
114
93
}
115
94
return util .SaveDir (chart , dest )
116
95
}
117
96
118
- func (s sdk ) GenerateChart (project * types.Project , dirname string ) error {
97
+ func (s SDK ) GenerateChart (project * types.Project , dirname string ) error {
119
98
if strings .Contains (dirname , "." ) {
120
99
splits := strings .SplitN (dirname , "." , 2 )
121
100
dirname = splits [0 ]
0 commit comments