@@ -2,7 +2,6 @@ package helmutils
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"io"
7
6
8
7
"github.com/kgateway-dev/kgateway/v2/pkg/utils/cmdutils"
@@ -16,77 +15,6 @@ type Client struct {
16
15
namespace string
17
16
}
18
17
19
- // InstallOpts is a set of typical options for a helm install which can be passed in
20
- // instead of requiring the caller to remember the helm cli flags. extraArgs should
21
- // always be accepted and respected when using InstallOpts.
22
- type InstallOpts struct {
23
- // KubeContext is the kubernetes context to use.
24
- KubeContext string
25
-
26
- // Namespace is the namespace to which the release will be installed.
27
- Namespace string
28
- // CreateNamespace controls whether to create the namespace or error if it doesn't exist.
29
- CreateNamespace bool
30
-
31
- // ValuesFile is the path to the YAML values for the installation.
32
- ValuesFile string
33
-
34
- // ReleaseName is the name of the release to install. Usually will be "gloo".
35
- ReleaseName string
36
-
37
- // Repository is the remote repo to use. Usually will be one of the constants exported
38
- // from this package. Ignored if LocalChartPath is set.
39
- Repository string
40
-
41
- // ChartName is the name of the chart to use. Usually will be "gloo". Ignored if LocalChartPath is set.
42
- ChartName string
43
-
44
- // LocalChartPath is the path to a locally built tarballed chart to install
45
- LocalChartPath string
46
- }
47
-
48
- func (o InstallOpts ) all () []string {
49
- return append ([]string {o .chart (), o .release ()}, o .flags ()... )
50
- }
51
-
52
- func (o InstallOpts ) flags () []string {
53
- args := []string {}
54
- appendIfNonEmpty := func (fld , flag string ) {
55
- if fld != "" {
56
- args = append (args , flag , fld )
57
- }
58
- }
59
-
60
- appendIfNonEmpty (o .KubeContext , "--kube-context" )
61
- appendIfNonEmpty (o .Namespace , "--namespace" )
62
- if o .CreateNamespace {
63
- args = append (args , "--create-namespace" )
64
- }
65
- appendIfNonEmpty (o .ValuesFile , "--values" )
66
-
67
- return args
68
- }
69
-
70
- func (o InstallOpts ) chart () string {
71
- if o .LocalChartPath != "" {
72
- return o .LocalChartPath
73
- }
74
-
75
- if o .Repository == "" || o .ChartName == "" {
76
- return RemoteChartName
77
- }
78
-
79
- return fmt .Sprintf ("%s/%s" , o .Repository , o .ChartName )
80
- }
81
-
82
- func (o InstallOpts ) release () string {
83
- if o .ReleaseName != "" {
84
- return o .ReleaseName
85
- }
86
-
87
- return ChartName
88
- }
89
-
90
18
// NewClient returns an implementation of the helmutils.Client
91
19
func NewClient () * Client {
92
20
return & Client {
@@ -126,11 +54,13 @@ func (c *Client) RunCommand(ctx context.Context, args ...string) error {
126
54
return c .Command (ctx , args ... ).Run ().Cause ()
127
55
}
128
56
129
- func (c * Client ) Install (ctx context.Context , extraArgs ... string ) error {
130
- args := append ([]string {
131
- "install" ,
132
- }, extraArgs ... )
57
+ func (c * Client ) Install (ctx context.Context , opts InstallOpts ) error {
58
+ args := append ([]string {"install" }, opts . all () ... )
59
+ return c . RunCommand ( ctx , args ... )
60
+ }
133
61
62
+ func (c * Client ) Uninstall (ctx context.Context , opts UninstallOpts ) error {
63
+ args := append ([]string {"uninstall" }, opts .all ()... )
134
64
return c .RunCommand (ctx , args ... )
135
65
}
136
66
@@ -151,16 +81,3 @@ func (c *Client) AddRepository(ctx context.Context, chartName string, chartUrl s
151
81
}, extraArgs ... )
152
82
return c .RunCommand (ctx , args ... )
153
83
}
154
-
155
- func (c * Client ) AddGlooRepository (ctx context.Context , extraArgs ... string ) error {
156
- return c .AddRepository (ctx , ChartName , ChartRepositoryUrl , extraArgs ... )
157
- }
158
-
159
- func (c * Client ) AddPrGlooRepository (ctx context.Context , extraArgs ... string ) error {
160
- return c .AddRepository (ctx , ChartName , PrChartRepositoryUrl , extraArgs ... )
161
- }
162
-
163
- func (c * Client ) InstallGloo (ctx context.Context , installOpts InstallOpts , extraArgs ... string ) error {
164
- args := append (installOpts .all (), extraArgs ... )
165
- return c .Install (ctx , args ... )
166
- }
0 commit comments