kubernetes-testing-framework icon indicating copy to clipboard operation
kubernetes-testing-framework copied to clipboard

Environments builder silently overwrites existing addons

Open pmalek opened this issue 1 year ago • 0 comments

Problem statement

https://github.com/Kong/kubernetes-testing-framework/pull/845 introduces an ability to deploy multiple kong addons into a cluster.

environment.Builder allows adding addons via WithAddons()

The problem with the current implementation is that it silently overwrites already added addons by name. So for instance if based on #845 we were to write:

	testNS1 := "kong-test-1"
	kong1 := kongaddon.NewBuilder().WithNamespace(testNS1).WithProxyServiceType(corev1.ServiceTypeClusterIP).Build()

	testNS2 := "kong-test-2"
	kong2 := kongaddon.NewBuilder().WithNamespace(testNS2).WithProxyServiceType(corev1.ServiceTypeClusterIP).Build()

	t.Log("configuring the testing environment")
	builder := environment.NewBuilder().WithAddons(kong1, kong2)

	t.Log("building the testing environment and Kubernetes cluster")
	env, err := builder.Build(ctx)
	require.NoError(t, err)

This would silently pass but the cluster would only get 1 addon deployed.

func (b *Builder) WithAddons(addons ...clusters.Addon) *Builder doesn't return an error so it cannot act when called with an addon that has a name that's already added.

Proposed solution

We have several options to address this:

  • make Builder.addons a slice not a map (of type type Addons map[AddonName]Addon)
  • make Builder.addons return an error when an addon with the same name (and type?) already exists

pmalek avatar Oct 20 '23 15:10 pmalek