Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kong): allow setting Node ports #844

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/clusters/addons/kong/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

shaneutt marked this conversation as resolved.
Show resolved Hide resolved
args = append(args, exposePortsDefault()...)
a.logger.Debugf("helm install arguments: %+v", args)

Expand Down Expand Up @@ -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",
Expand Down
27 changes: 26 additions & 1 deletion pkg/clusters/addons/kong/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,8 +79,14 @@ func (b *Builder) Build() *Addon {
}

// LoadBalancer is used by default for historical and convenience reasons.
if b.proxyServiceType == "" {
switch b.proxyServiceType { //nolint:exhaustive
case "":
b.proxyServiceType = corev1.ServiceTypeLoadBalancer
case corev1.ServiceTypeNodePort:
// If the proxy service type is NodePort, then set the default proxy NodePort.
if b.httpNodePort == 0 {
b.httpNodePort = DefaultProxyNodePort
}
}

return &Addon{
Expand Down Expand Up @@ -105,6 +115,9 @@ func (b *Builder) Build() *Addon {
proxyEnterpriseLicenseJSON: b.proxyEnterpriseLicenseJSON,
proxyEnterpriseSuperAdminPassword: b.proxyEnterpriseSuperAdminPassword,

httpNodePort: b.httpNodePort,
adminNodePort: b.adminNodePort,

additionalValues: b.additionalValues,
}
}
Expand Down Expand Up @@ -239,3 +252,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
}
4 changes: 4 additions & 0 deletions pkg/clusters/addons/kong/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
shaneutt marked this conversation as resolved.
Show resolved Hide resolved
)
12 changes: 6 additions & 6 deletions pkg/clusters/addons/metallb/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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{})
}
Expand Down Expand Up @@ -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{})
}
Expand Down
Loading