From 5e9af50486d9960ce7ab12f2b6a8db59de5ec7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Fri, 20 Oct 2023 13:04:00 +0200 Subject: [PATCH] feat(kong): allow setting Node ports --- pkg/clusters/addons/kong/addon.go | 16 +++++++++++++--- pkg/clusters/addons/kong/builder.go | 19 +++++++++++++++++++ pkg/clusters/addons/kong/vars.go | 4 ++++ pkg/clusters/addons/metallb/metallb.go | 12 ++++++------ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/pkg/clusters/addons/kong/addon.go b/pkg/clusters/addons/kong/addon.go index 53d9e97da..e84786b9c 100644 --- a/pkg/clusters/addons/kong/addon.go +++ b/pkg/clusters/addons/kong/addon.go @@ -95,6 +95,10 @@ type Addon struct { proxyEnvVars map[string]string proxyReadinessProbePath string + // Node ports + httpNodePort int + adminNodePort int + // proxy server enterprise mode configuration options proxyEnterpriseEnabled bool proxyEnterpriseSuperAdminPassword string @@ -175,7 +179,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 { @@ -372,6 +376,14 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error { args = append(args, "--namespace", a.namespace) args = append(args, a.deployArgs...) args = append(args, defaults()...) + + if a.httpNodePort > 0 { + args = append(args, "--set", fmt.Sprintf("proxy.http.nodePort=%d", a.httpNodePort)) + } + if a.adminNodePort > 0 { + args = append(args, "--set", fmt.Sprintf("admin.http.nodePort=%d", a.adminNodePort)) + } + args = append(args, exposePortsDefault()...) a.logger.Debugf("helm install arguments: %+v", args) @@ -573,10 +585,8 @@ func defaults() []string { return []string{ // we configure a cluster network exposed admin API over HTTP with no auth for testing convenience, // but again keep in mind this is meant ONLY for transient testing scenarios and isn't secure. - "--set", "proxy.http.nodePort=30080", "--set", "admin.enabled=true", "--set", "admin.http.enabled=true", - "--set", "admin.http.nodePort=32080", "--set", "admin.tls.enabled=false", "--set", "tls.enabled=false", "--set", "udpProxy.enabled=true", diff --git a/pkg/clusters/addons/kong/builder.go b/pkg/clusters/addons/kong/builder.go index e34e72f16..6dc333a92 100644 --- a/pkg/clusters/addons/kong/builder.go +++ b/pkg/clusters/addons/kong/builder.go @@ -37,6 +37,10 @@ type Builder struct { proxyEnvVars map[string]string proxyReadinessProbePath string + // ports + httpNodePort int + adminNodePort int + // proxy server enterprise mode configuration options proxyEnterpriseEnabled bool proxyEnterpriseSuperAdminPassword string @@ -105,6 +109,9 @@ func (b *Builder) Build() *Addon { proxyEnterpriseLicenseJSON: b.proxyEnterpriseLicenseJSON, proxyEnterpriseSuperAdminPassword: b.proxyEnterpriseSuperAdminPassword, + httpNodePort: b.httpNodePort, + adminNodePort: b.adminNodePort, + additionalValues: b.additionalValues, } } @@ -239,3 +246,15 @@ func (b *Builder) WithAdditionalValue(name, value string) *Builder { b.additionalValues[name] = value return b } + +// WithHTTPNodePort sets the HTTP Nodeport. +func (b *Builder) WithHTTPNodePort(port int) *Builder { + b.httpNodePort = port + return b +} + +// WithAdminNodePort sets the HTTP Nodeport. +func (b *Builder) WithAdminNodePort(port int) *Builder { + b.adminNodePort = port + return b +} diff --git a/pkg/clusters/addons/kong/vars.go b/pkg/clusters/addons/kong/vars.go index e445b2e71..cc11683d2 100644 --- a/pkg/clusters/addons/kong/vars.go +++ b/pkg/clusters/addons/kong/vars.go @@ -53,4 +53,8 @@ const ( // DefaultProxyNodePort indicates the default NodePort that will be used for // the proxy when applicable. DefaultProxyNodePort = 30080 + + // DefaultAdminNodePort indicates the default NodePort that will be used for + // the admin API when applicable. + DefaultAdminNodePort = 32080 ) diff --git a/pkg/clusters/addons/metallb/metallb.go b/pkg/clusters/addons/metallb/metallb.go index 2c8746ce3..79bdd92b5 100644 --- a/pkg/clusters/addons/metallb/metallb.go +++ b/pkg/clusters/addons/metallb/metallb.go @@ -13,7 +13,7 @@ import ( "go4.org/netipx" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -121,7 +121,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime. deployment, err := cluster.Client().AppsV1().Deployments(DefaultNamespace). Get(ctx, "controller", metav1.GetOptions{}) if err != nil { - if errors.IsNotFound(err) { + if apierrors.IsNotFound(err) { return nil, false, nil } return nil, false, err @@ -157,7 +157,7 @@ func (a *Addon) deployMetallbForKindCluster(ctx context.Context, cluster cluster // 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 { - if !errors.IsAlreadyExists(err) { + if !apierrors.IsAlreadyExists(err) { return err } } @@ -194,7 +194,7 @@ func (a *Addon) deployMetallbForKindCluster(ctx context.Context, cluster cluster }, } if _, err := cluster.Client().CoreV1().Secrets(ns.Name).Create(ctx, secret, metav1.CreateOptions{}); err != nil { - if !errors.IsAlreadyExists(err) { + if !apierrors.IsAlreadyExists(err) { return err } } @@ -243,7 +243,7 @@ func createIPAddressPool(ctx context.Context, cluster clusters.Cluster, dockerNe }, metav1.CreateOptions{}) if err != nil { - if errors.IsAlreadyExists(err) { + if apierrors.IsAlreadyExists(err) { // delete the existing resource and recreate it in another round of loop. err = res.Delete(ctx, addressPoolName, metav1.DeleteOptions{}) } @@ -286,7 +286,7 @@ func createL2Advertisement(ctx context.Context, cluster clusters.Cluster) error }, metav1.CreateOptions{}) if err != nil { - if errors.IsAlreadyExists(err) { + if apierrors.IsAlreadyExists(err) { // delete the existing resource and recreate it in another round of loop. err = res.Delete(ctx, l2AdvertisementName, metav1.DeleteOptions{}) }