Skip to content

Commit

Permalink
fix(ipv6): Use net.JoinHostPort instead of fmt.Sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
johannwagner committed Jul 10, 2024
1 parent f4c0cec commit b1b2153
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ConnectionEndpoint struct {
}

func (r ConnectionEndpoint) String() string {
return fmt.Sprintf("%s:%d", r.Host, r.Port)
return net.JoinHostPort(r.Host, strconv.FormatInt(int64(r.Port), 10))
}

type ConnectionConfig struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/resources/k8s_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package resources

import (
"context"
"fmt"
"net"
"strconv"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -53,8 +54,7 @@ func (r *KubernetesServiceResource) UpdateTenantControlPlaneStatus(ctx context.C

return err
}

tenantControlPlane.Status.ControlPlaneEndpoint = fmt.Sprintf("%s:%d", address, tenantControlPlane.Spec.NetworkProfile.Port)
tenantControlPlane.Status.ControlPlaneEndpoint = net.JoinHostPort(address, strconv.FormatInt(int64(tenantControlPlane.Spec.NetworkProfile.Port), 10))

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions internal/resources/kubeadm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package resources

import (
"context"
"fmt"
"net"
"strconv"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -74,7 +75,7 @@ func (r *KubeadmConfigResource) getControlPlaneEndpoint(ingress *kamajiv1alpha1.
address, port = utilities.GetControlPlaneAddressAndPortFromHostname(ingress.Hostname, port)
}

return fmt.Sprintf("%s:%d", address, port)
return net.JoinHostPort(address, strconv.FormatInt(int64(port), 10))
}

func (r *KubeadmConfigResource) mutate(ctx context.Context, tenantControlPlane *kamajiv1alpha1.TenantControlPlane) controllerutil.MutateFn {
Expand Down

0 comments on commit b1b2153

Please sign in to comment.