From 8aded7579a12c5bca66af05e610b828af7f93993 Mon Sep 17 00:00:00 2001 From: Travis Raines <571832+rainest@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:12:49 -0800 Subject: [PATCH] feat: support arbitrary Kuma Helm values --- CHANGELOG.md | 5 +++++ pkg/clusters/addons/kuma/addon.go | 8 +++++++- pkg/clusters/addons/kuma/builder.go | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d693ef51..5de257af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Added support for arbitrary Helm chart values to the Kuma plugin. + [#958](https://github.com/Kong/kubernetes-testing-framework/pull/958) + ## v0.45.0 - `Kuma` addon now properly uses the Helm chart version passed in its builder's diff --git a/pkg/clusters/addons/kuma/addon.go b/pkg/clusters/addons/kuma/addon.go index 75dc3dec..6d038824 100644 --- a/pkg/clusters/addons/kuma/addon.go +++ b/pkg/clusters/addons/kuma/addon.go @@ -47,7 +47,8 @@ type Addon struct { version *semver.Version - mtlsEnabled bool + mtlsEnabled bool + additionalValues map[string]string } // New produces a new clusters.Addon for Kuma with MTLS enabled @@ -155,6 +156,11 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error { // compile the helm installation values args = append(args, "--create-namespace", "--namespace", Namespace) + + for name, value := range a.additionalValues { + args = append(args, "--set", fmt.Sprintf("%s=%s", name, value)) + } + a.logger.Debugf("helm install arguments: %+v", args) // Sometimes running helm install fails. Just in case this happens, retry. diff --git a/pkg/clusters/addons/kuma/builder.go b/pkg/clusters/addons/kuma/builder.go index 8bde3c59..a0305c23 100644 --- a/pkg/clusters/addons/kuma/builder.go +++ b/pkg/clusters/addons/kuma/builder.go @@ -17,13 +17,15 @@ type Builder struct { version *semver.Version logger *logrus.Logger - mtlsEnabled bool + mtlsEnabled bool + additionalValues map[string]string } // NewBuilder provides a new Builder object for configuring Kuma cluster addons. func NewBuilder() *Builder { return &Builder{ - name: string(AddonName), + name: string(AddonName), + additionalValues: make(map[string]string), } } @@ -48,6 +50,12 @@ func (b *Builder) WithMTLS() *Builder { return b } +// WithAdditionalValue sets a key and value to pass to Helm using --set. +func (b *Builder) WithAdditionalValue(name, value string) *Builder { + b.additionalValues[name] = value + return b +} + // Build generates a new kong cluster.Addon which can be loaded and deployed // into a test Environment's cluster.Cluster. func (b *Builder) Build() *Addon { @@ -59,6 +67,7 @@ func (b *Builder) Build() *Addon { version: b.version, logger: b.logger, - mtlsEnabled: b.mtlsEnabled, + mtlsEnabled: b.mtlsEnabled, + additionalValues: b.additionalValues, } }