Skip to content

Commit

Permalink
feat(kong): allow multiple kong addons to be deployed in cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 20, 2023
1 parent 8ce2ab2 commit c4c7054
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
12 changes: 7 additions & 5 deletions pkg/clusters/addons/kong/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ const (
type Addon struct {
logger *logrus.Logger

name string

// kubernetes and helm chart related configuration options
namespace string
name string
deployArgs []string
chartVersion string
namespace string
helmReleaseName string
deployArgs []string
chartVersion string

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

func (a *Addon) Name() clusters.AddonName {
return AddonName
return clusters.AddonName(a.name)
}

func (a *Addon) Dependencies(_ context.Context, cluster clusters.Cluster) []clusters.AddonName {
Expand Down
31 changes: 22 additions & 9 deletions pkg/clusters/addons/kong/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
corev1 "k8s.io/api/core/v1"
)

const (
DefaultKongAddonName = "kong"
)

// -----------------------------------------------------------------------------
// Kong Addon - Builder
// -----------------------------------------------------------------------------
Expand All @@ -15,11 +19,13 @@ import (
type Builder struct {
logger *logrus.Logger

name string

// kubernetes and helm chart related configuration options
namespace string
name string
deployArgs []string
chartVersion string
namespace string
helmReleaseName string
deployArgs []string
chartVersion string

// ingress controller configuration options
ingressControllerDisabled bool
Expand Down Expand Up @@ -54,8 +60,9 @@ type Builder struct {
// Kong Addon objects which can be deployed to cluster.Clusters
func NewBuilder() *Builder {
builder := &Builder{
name: DefaultKongAddonName,
namespace: DefaultNamespace,
name: DefaultDeploymentName,
helmReleaseName: DefaultDeploymentName,
deployArgs: []string{},
proxyEnvVars: make(map[string]string),
additionalValues: make(map[string]string),
Expand Down Expand Up @@ -92,10 +99,10 @@ func (b *Builder) Build() *Addon {
return &Addon{
logger: b.logger,

namespace: b.namespace,
name: b.name,
deployArgs: b.deployArgs,
chartVersion: b.chartVersion,
namespace: b.namespace,
helmReleaseName: b.helmReleaseName,
deployArgs: b.deployArgs,
chartVersion: b.chartVersion,

ingressControllerDisabled: b.ingressControllerDisabled,
ingressControllerImage: b.ingressControllerImage,
Expand Down Expand Up @@ -264,3 +271,9 @@ func (b *Builder) WithAdminNodePort(port int) *Builder {
b.adminNodePort = port
return b
}

// WithName sets the addon name.
func (b *Builder) WithName(name string) *Builder {
b.name = name
return b
}
38 changes: 38 additions & 0 deletions test/integration/kongaddon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,41 @@ func TestKongUDPProxy(t *testing.T) {
return false
}, time.Minute*3, time.Second)
}

func TestKongAddonMultiplePerCluster(t *testing.T) {
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)

err = <-env.WaitForReady(ctx)
require.NoError(t, err)

t.Log("verifying that kong addon have been loaded into the environment")
require.Len(t, env.Cluster().ListAddons(), 2)

apps := env.Cluster().Client().AppsV1()
t.Log("verifying that kong deployments are deployed in their namespaces")
{
deployments := apps.Deployments(testNS1)
kongDeployment, err := deployments.Get(ctx, "ingress-controller-kong", metav1.GetOptions{})
require.NoError(t, err)
require.Greater(t, int(kongDeployment.Status.ReadyReplicas), 0, "should have at least one ready replicas")
require.Equal(t, kongDeployment.Status.Replicas, kongDeployment.Status.ReadyReplicas, "replicas should be all ready")
}
{
deployments := apps.Deployments(testNS2)
kongDeployment, err := deployments.Get(ctx, "ingress-controller-kong", metav1.GetOptions{})
require.NoError(t, err)
require.Greater(t, int(kongDeployment.Status.ReadyReplicas), 0, "should have at least one ready replicas")
require.Equal(t, kongDeployment.Status.Replicas, kongDeployment.Status.ReadyReplicas, "replicas should be all ready")
}
}

0 comments on commit c4c7054

Please sign in to comment.