Skip to content

Commit 3ef5a55

Browse files
authored
update e2e helm install (#10632)
Signed-off-by: Jenny Shu <[email protected]>
1 parent 1f2d6a3 commit 3ef5a55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+399
-950
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/golang/mock v1.6.0
1919
github.com/google/go-cmp v0.6.0
2020
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
21+
github.com/hashicorp/go-multierror v1.1.1
2122
github.com/kelseyhightower/envconfig v1.4.0
2223
github.com/onsi/ginkgo/v2 v2.20.2
2324
github.com/onsi/gomega v1.35.0
@@ -129,7 +130,6 @@ require (
129130
github.com/gosuri/uitable v0.0.4 // indirect
130131
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
131132
github.com/hashicorp/errwrap v1.1.0 // indirect
132-
github.com/hashicorp/go-multierror v1.1.1 // indirect
133133
github.com/hashicorp/hcl v1.0.0 // indirect
134134
github.com/huandu/xstrings v1.5.0 // indirect
135135
github.com/imdario/mergo v1.0.0 // indirect
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name|Version|License
2+
---|---|---
3+
[hashicorp/go-multierror](https://github.com/hashicorp/go-multierror)|v1.1.1|Mozilla Public License 2.0

pkg/utils/helmutils/client.go

+6-89
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package helmutils
22

33
import (
44
"context"
5-
"fmt"
65
"io"
76

87
"github.com/kgateway-dev/kgateway/v2/pkg/utils/cmdutils"
@@ -16,77 +15,6 @@ type Client struct {
1615
namespace string
1716
}
1817

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-
9018
// NewClient returns an implementation of the helmutils.Client
9119
func NewClient() *Client {
9220
return &Client{
@@ -126,11 +54,13 @@ func (c *Client) RunCommand(ctx context.Context, args ...string) error {
12654
return c.Command(ctx, args...).Run().Cause()
12755
}
12856

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+
}
13361

62+
func (c *Client) Uninstall(ctx context.Context, opts UninstallOpts) error {
63+
args := append([]string{"uninstall"}, opts.all()...)
13464
return c.RunCommand(ctx, args...)
13565
}
13666

@@ -151,16 +81,3 @@ func (c *Client) AddRepository(ctx context.Context, chartName string, chartUrl s
15181
}, extraArgs...)
15282
return c.RunCommand(ctx, args...)
15383
}
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-
}

pkg/utils/helmutils/constants.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
package helmutils
22

3-
import "fmt"
4-
53
const (
6-
ChartName = "gloo"
4+
ChartName = "kgateway"
75

8-
ChartRepositoryUrl = "https://storage.googleapis.com/solo-public-helm"
9-
PrChartRepositoryUrl = "https://storage.googleapis.com/solo-public-tagged-helm"
10-
RemoteChartUriTemplate = "https://storage.googleapis.com/solo-public-helm/charts/gloo-%s.tgz"
11-
RemoteChartName = "gloo/gloo"
6+
DefaultChartUri = "oci://ghcr.io/kgateway-dev/charts/kgateway"
127
)
13-
14-
func GetRemoteChartUri(version string) string {
15-
return fmt.Sprintf(RemoteChartUriTemplate, version)
16-
}

pkg/utils/helmutils/install.go

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package helmutils
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// InstallOpts is a set of typical options for a helm install which can be passed in
8+
// instead of requiring the caller to remember the helm cli flags.
9+
type InstallOpts struct {
10+
// KubeContext is the kubernetes context to use.
11+
KubeContext string
12+
13+
// Namespace is the namespace to which the release will be installed.
14+
Namespace string
15+
16+
// CreateNamespace controls whether to create the namespace or error if it doesn't exist.
17+
CreateNamespace bool
18+
19+
// ValuesFiles is a list of absolute paths to YAML values for the installation. They will be
20+
// applied in the order they are specified.
21+
ValuesFiles []string
22+
23+
// ExtraArgs allows passing in arbitrary extra arguments to the install.
24+
ExtraArgs []string
25+
26+
// ReleaseName is the name of the release to install.
27+
ReleaseName string
28+
29+
// Repository is the remote repo to use. Ignored if ChartUri is set.
30+
Repository string
31+
32+
// ChartName is the name of the chart to use. Ignored if ChartUri is set.
33+
ChartName string
34+
35+
// ChartUri may refer to a local chart path (e.g. to a tgz file) or a remote chart uri (e.g. oci://...) to install.
36+
// If provided, then Repository and ChartName are ignored.
37+
ChartUri string
38+
39+
// Version can be used to install a specific release version (e.g. v2.0.0)
40+
Version string
41+
}
42+
43+
func (o InstallOpts) all() []string {
44+
return append([]string{o.release(), o.chart()}, o.flags()...)
45+
}
46+
47+
func (o InstallOpts) flags() []string {
48+
args := []string{}
49+
appendIfNonEmpty := func(flagVal, flagName string) {
50+
if flagVal != "" {
51+
args = append(args, flagName, flagVal)
52+
}
53+
}
54+
55+
appendIfNonEmpty(o.KubeContext, "--kube-context")
56+
appendIfNonEmpty(o.Namespace, "--namespace")
57+
if o.CreateNamespace {
58+
args = append(args, "--create-namespace")
59+
}
60+
appendIfNonEmpty(o.Version, "--version")
61+
for _, valsFile := range o.ValuesFiles {
62+
appendIfNonEmpty(valsFile, "--values")
63+
}
64+
for _, extraArg := range o.ExtraArgs {
65+
args = append(args, extraArg)
66+
}
67+
68+
return args
69+
}
70+
71+
func (o InstallOpts) chart() string {
72+
if o.ChartUri != "" {
73+
return o.ChartUri
74+
}
75+
76+
if o.Repository != "" && o.ChartName != "" {
77+
return fmt.Sprintf("%s/%s", o.Repository, o.ChartName)
78+
}
79+
80+
return DefaultChartUri
81+
}
82+
83+
func (o InstallOpts) release() string {
84+
if o.ReleaseName != "" {
85+
return o.ReleaseName
86+
}
87+
88+
return ChartName
89+
}

pkg/utils/helmutils/uninstall.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package helmutils
2+
3+
// UninstallOpts is a set of typical options for a helm uninstall which can be passed in
4+
// instead of requiring the caller to remember the helm cli flags.
5+
type UninstallOpts struct {
6+
// KubeContext is the kubernetes context to use.
7+
KubeContext string
8+
9+
// Namespace is the namespace to which the release was installed.
10+
Namespace string
11+
12+
// ReleaseName is the name of the release to uninstall.
13+
ReleaseName string
14+
15+
// ExtraArgs allows passing in arbitrary extra arguments to the uninstall.
16+
ExtraArgs []string
17+
}
18+
19+
func (o UninstallOpts) all() []string {
20+
return append([]string{o.release()}, o.flags()...)
21+
}
22+
23+
func (o UninstallOpts) flags() []string {
24+
args := []string{}
25+
appendIfNonEmpty := func(flagVal, flagName string) {
26+
if flagVal != "" {
27+
args = append(args, flagName, flagVal)
28+
}
29+
}
30+
31+
appendIfNonEmpty(o.KubeContext, "--kube-context")
32+
appendIfNonEmpty(o.Namespace, "--namespace")
33+
34+
for _, extraArg := range o.ExtraArgs {
35+
args = append(args, extraArg)
36+
}
37+
38+
return args
39+
}
40+
41+
func (o UninstallOpts) release() string {
42+
if o.ReleaseName != "" {
43+
return o.ReleaseName
44+
}
45+
46+
return ChartName
47+
}

test/gomega/matchers/pod.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build ignore
2-
31
package matchers
42

53
import (

test/helpers/kube_dump.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build ignore
2-
31
package helpers
42

53
import (

test/kubernetes/e2e/example/info_logging_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/kgateway-dev/kgateway/v2/pkg/utils/envutils"
15-
"github.com/kgateway-dev/kgateway/v2/test/testutils"
16-
1714
"github.com/stretchr/testify/suite"
1815

16+
"github.com/kgateway-dev/kgateway/v2/pkg/utils/envutils"
1917
"github.com/kgateway-dev/kgateway/v2/pkg/utils/fsutils"
20-
2118
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/e2e"
2219
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/e2e/features/example"
23-
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/testutils/kgateway"
20+
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/testutils/install"
21+
"github.com/kgateway-dev/kgateway/v2/test/testutils"
2422
)
2523

2624
// TestInstallationWithInfoLogLevel is the function which executes a series of tests against a given installation
@@ -29,7 +27,7 @@ func TestInstallationWithInfoLogLevel(t *testing.T) {
2927
installNs, nsEnvPredefined := envutils.LookupOrDefault(testutils.InstallNamespace, "info-log-test")
3028
testInstallation := e2e.CreateTestInstallation(
3129
t,
32-
&kgateway.Context{
30+
&install.Context{
3331
InstallNamespace: installNs,
3432
ProfileValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "example-profile.yaml"),
3533
ValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "info-example.yaml"),

test/kubernetes/e2e/suite.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build ignore
2-
31
package e2e
42

53
import (

0 commit comments

Comments
 (0)