Skip to content

Commit

Permalink
fix(ingress): referencing ingress port from hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed Aug 8, 2023
1 parent adde828 commit 6585472
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/resources/k8s_ingress_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (r *KubernetesIngressResource) mutate(tenantControlPlane *kamajiv1alpha1.Te
return fmt.Errorf("missing hostname to expose the Tenant Control Plane using an Ingress resource")
}

rule.Host = tenantControlPlane.Spec.ControlPlane.Ingress.Hostname
rule.Host, _ = utilities.GetControlPlaneAddressAndPortFromHostname(tenantControlPlane.Spec.ControlPlane.Ingress.Hostname, 0)

r.resource.Spec.Rules = []networkingv1.IngressRule{
rule,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/kubeadm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *KubeadmConfigResource) UpdateTenantControlPlaneStatus(ctx context.Conte

func (r *KubeadmConfigResource) getControlPlaneEndpoint(ingress *kamajiv1alpha1.IngressSpec, address string, port int32) string {
if ingress != nil && len(ingress.Hostname) > 0 {
return ingress.Hostname
address, port = utilities.GetControlPlaneAddressAndPortFromHostname(ingress.Hostname, port)
}

return fmt.Sprintf("%s:%d", address, port)
Expand Down
25 changes: 25 additions & 0 deletions internal/utilities/ingress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2022 Clastix Labs
// SPDX-License-Identifier: Apache-2.0

package utilities

import (
"strconv"
"strings"
)

func GetControlPlaneAddressAndPortFromHostname(hostname string, defaultPort int32) (address string, port int32) {
parts := strings.Split(hostname, ":")

address, port = parts[0], defaultPort

if len(parts) == 2 {
intPort, _ := strconv.Atoi(parts[1])

if intPort > 0 {
port = int32(intPort)
}
}

return address, port
}

0 comments on commit 6585472

Please sign in to comment.