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

fix(ipv6): Use net.JoinHostPort instead of fmt.Sprintf #485

Merged
merged 1 commit into from
Jul 11, 2024
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
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
Loading