Skip to content

Commit c4c7054

Browse files
committed
feat(kong): allow multiple kong addons to be deployed in cluster
1 parent 8ce2ab2 commit c4c7054

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

pkg/clusters/addons/kong/addon.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ const (
7373
type Addon struct {
7474
logger *logrus.Logger
7575

76+
name string
77+
7678
// kubernetes and helm chart related configuration options
77-
namespace string
78-
name string
79-
deployArgs []string
80-
chartVersion string
79+
namespace string
80+
helmReleaseName string
81+
deployArgs []string
82+
chartVersion string
8183

8284
// ingress controller configuration options
8385
ingressControllerDisabled bool
@@ -179,7 +181,7 @@ func (a *Addon) ProxyUDPURL(ctx context.Context, cluster clusters.Cluster) (*url
179181
// -----------------------------------------------------------------------------
180182

181183
func (a *Addon) Name() clusters.AddonName {
182-
return AddonName
184+
return clusters.AddonName(a.name)
183185
}
184186

185187
func (a *Addon) Dependencies(_ context.Context, cluster clusters.Cluster) []clusters.AddonName {

pkg/clusters/addons/kong/builder.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
corev1 "k8s.io/api/core/v1"
88
)
99

10+
const (
11+
DefaultKongAddonName = "kong"
12+
)
13+
1014
// -----------------------------------------------------------------------------
1115
// Kong Addon - Builder
1216
// -----------------------------------------------------------------------------
@@ -15,11 +19,13 @@ import (
1519
type Builder struct {
1620
logger *logrus.Logger
1721

22+
name string
23+
1824
// kubernetes and helm chart related configuration options
19-
namespace string
20-
name string
21-
deployArgs []string
22-
chartVersion string
25+
namespace string
26+
helmReleaseName string
27+
deployArgs []string
28+
chartVersion string
2329

2430
// ingress controller configuration options
2531
ingressControllerDisabled bool
@@ -54,8 +60,9 @@ type Builder struct {
5460
// Kong Addon objects which can be deployed to cluster.Clusters
5561
func NewBuilder() *Builder {
5662
builder := &Builder{
63+
name: DefaultKongAddonName,
5764
namespace: DefaultNamespace,
58-
name: DefaultDeploymentName,
65+
helmReleaseName: DefaultDeploymentName,
5966
deployArgs: []string{},
6067
proxyEnvVars: make(map[string]string),
6168
additionalValues: make(map[string]string),
@@ -92,10 +99,10 @@ func (b *Builder) Build() *Addon {
9299
return &Addon{
93100
logger: b.logger,
94101

95-
namespace: b.namespace,
96-
name: b.name,
97-
deployArgs: b.deployArgs,
98-
chartVersion: b.chartVersion,
102+
namespace: b.namespace,
103+
helmReleaseName: b.helmReleaseName,
104+
deployArgs: b.deployArgs,
105+
chartVersion: b.chartVersion,
99106

100107
ingressControllerDisabled: b.ingressControllerDisabled,
101108
ingressControllerImage: b.ingressControllerImage,
@@ -264,3 +271,9 @@ func (b *Builder) WithAdminNodePort(port int) *Builder {
264271
b.adminNodePort = port
265272
return b
266273
}
274+
275+
// WithName sets the addon name.
276+
func (b *Builder) WithName(name string) *Builder {
277+
b.name = name
278+
return b
279+
}

test/integration/kongaddon_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,41 @@ func TestKongUDPProxy(t *testing.T) {
333333
return false
334334
}, time.Minute*3, time.Second)
335335
}
336+
337+
func TestKongAddonMultiplePerCluster(t *testing.T) {
338+
testNS1 := "kong-test-1"
339+
kong1 := kongaddon.NewBuilder().WithNamespace(testNS1).WithProxyServiceType(corev1.ServiceTypeClusterIP).Build()
340+
341+
testNS2 := "kong-test-2"
342+
kong2 := kongaddon.NewBuilder().WithNamespace(testNS2).WithProxyServiceType(corev1.ServiceTypeClusterIP).Build()
343+
344+
t.Log("configuring the testing environment")
345+
builder := environment.NewBuilder().WithAddons(kong1, kong2)
346+
347+
t.Log("building the testing environment and Kubernetes cluster")
348+
env, err := builder.Build(ctx)
349+
require.NoError(t, err)
350+
351+
err = <-env.WaitForReady(ctx)
352+
require.NoError(t, err)
353+
354+
t.Log("verifying that kong addon have been loaded into the environment")
355+
require.Len(t, env.Cluster().ListAddons(), 2)
356+
357+
apps := env.Cluster().Client().AppsV1()
358+
t.Log("verifying that kong deployments are deployed in their namespaces")
359+
{
360+
deployments := apps.Deployments(testNS1)
361+
kongDeployment, err := deployments.Get(ctx, "ingress-controller-kong", metav1.GetOptions{})
362+
require.NoError(t, err)
363+
require.Greater(t, int(kongDeployment.Status.ReadyReplicas), 0, "should have at least one ready replicas")
364+
require.Equal(t, kongDeployment.Status.Replicas, kongDeployment.Status.ReadyReplicas, "replicas should be all ready")
365+
}
366+
{
367+
deployments := apps.Deployments(testNS2)
368+
kongDeployment, err := deployments.Get(ctx, "ingress-controller-kong", metav1.GetOptions{})
369+
require.NoError(t, err)
370+
require.Greater(t, int(kongDeployment.Status.ReadyReplicas), 0, "should have at least one ready replicas")
371+
require.Equal(t, kongDeployment.Status.Replicas, kongDeployment.Status.ReadyReplicas, "replicas should be all ready")
372+
}
373+
}

0 commit comments

Comments
 (0)