Kong / Kong/kubernetes-testing-framework
Environments builder silently overwrites existing addons
- Dominant language
- Go
- Stars
- 44
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
### 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()`](https://github.com/Kong/kubernetes-testing-framework/blob/0dab64760e88b208e0b7e4dd52a2ada3ca71e230/pkg/environments/builder.go#L46-L53)
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
Contributor guide
Research direction
Read pkg/environments/builder.go, especially WithAddons and the Addons map type, then trace how Builder.Build consumes the collection. The duplicate-name policy still needs maintainer agreement because the issue presents multiple API options. Done means adding kong1 and kong2 with distinct namespaces no longer silently deploys only one addon, with the behavior verified by environment tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- infrastructure, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100