diff --git a/CHANGELOG.md b/CHANGELOG.md index 50ccc3190..5cd413426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.40.0 + +- Metallb addon now has a builder. The builder can disable IPAddressPool + creation. + [#835](https://github.com/Kong/kubernetes-testing-framework/pull/835) + ## v0.39.1 - Removed a module exclude that made `go install` unhappy. diff --git a/pkg/clusters/addons/metallb/metallb.go b/pkg/clusters/addons/metallb/metallb.go index 000afcb12..700ceb61b 100644 --- a/pkg/clusters/addons/metallb/metallb.go +++ b/pkg/clusters/addons/metallb/metallb.go @@ -58,7 +58,9 @@ var ( } ) -type addon struct{} +type addon struct { + disablePoolCreation bool +} func New() clusters.Addon { return &addon{} @@ -81,7 +83,7 @@ func (a *addon) Deploy(ctx context.Context, cluster clusters.Cluster) error { return fmt.Errorf("the metallb addon is currently only supported on %s clusters", kind.KindClusterType) } - return deployMetallbForKindCluster(ctx, cluster, kind.DefaultKindDockerNetwork) + return a.deployMetallbForKindCluster(ctx, cluster, kind.DefaultKindDockerNetwork) } func (a *addon) Delete(ctx context.Context, cluster clusters.Cluster) error { @@ -151,7 +153,7 @@ var ( // ----------------------------------------------------------------------------- // deployMetallbForKindCluster deploys Metallb to the given Kind cluster using the Docker network provided for LoadBalancer IPs. -func deployMetallbForKindCluster(ctx context.Context, cluster clusters.Cluster, dockerNetwork string) error { +func (a *addon) deployMetallbForKindCluster(ctx context.Context, cluster clusters.Cluster, dockerNetwork string) error { // ensure the namespace for metallb is created ns := corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: DefaultNamespace}} if _, err := cluster.Client().CoreV1().Namespaces().Create(ctx, &ns, metav1.CreateOptions{}); err != nil { @@ -167,8 +169,10 @@ func deployMetallbForKindCluster(ctx context.Context, cluster clusters.Cluster, } // create an ip address pool - if err := createIPAddressPool(ctx, cluster, dockerNetwork); err != nil { - return err + if !a.disablePoolCreation { + if err := createIPAddressPool(ctx, cluster, dockerNetwork); err != nil { + return err + } } if err := createL2Advertisement(ctx, cluster); err != nil { @@ -400,3 +404,33 @@ func metallbDeleteHack(ctx context.Context, kubeconfig *os.File) error { WithStdout(io.Discard). Do(ctx) } + +// ----------------------------------------------------------------------------- +// Metallb Builder +// ----------------------------------------------------------------------------- + +// Builder is a configuration tool for metallb cluster.Addons. +type Builder struct { + disablePoolCreation bool +} + +// NewBuilder provides a new Builder object with default addon settings. +func NewBuilder() *Builder { + builder := &Builder{ + disablePoolCreation: false, + } + return builder +} + +// WithPoolDisabled instructs the builder to create addons with pool creation disabled. +func (b *Builder) WithPoolDisabled() *Builder { + b.disablePoolCreation = true + return b +} + +// Build generates an addon with the builder's configuration. +func (b *Builder) Build() *addon { + return &addon{ + disablePoolCreation: b.disablePoolCreation, + } +}