From 8cc255a26da90e4781c8610d003251500e026630 Mon Sep 17 00:00:00 2001 From: Tom Mychost Date: Mon, 25 Nov 2024 06:49:56 +0000 Subject: [PATCH] Replace Sprintf with JoinHostPort to support colons in IPv6 addresses. (#264) Closes #192 Signed-off-by: Tom Mychost --- internal/controller/dragonfly_instance.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/controller/dragonfly_instance.go b/internal/controller/dragonfly_instance.go index c094d4d..0e2b143 100644 --- a/internal/controller/dragonfly_instance.go +++ b/internal/controller/dragonfly_instance.go @@ -20,6 +20,8 @@ import ( "context" "errors" "fmt" + "net" + "strconv" "strings" dfv1alpha1 "github.com/dragonflydb/dragonfly-operator/api/v1alpha1" @@ -329,7 +331,7 @@ func (dfi *DragonflyInstance) getPods(ctx context.Context) (*corev1.PodList, err // to the given master instance func (dfi *DragonflyInstance) replicaOf(ctx context.Context, pod *corev1.Pod, masterIp string) error { redisClient := redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("%s:%d", pod.Status.PodIP, resources.DragonflyAdminPort), + Addr: net.JoinHostPort(pod.Status.PodIP, strconv.Itoa(resources.DragonflyAdminPort)), }) defer redisClient.Close() @@ -357,7 +359,7 @@ func (dfi *DragonflyInstance) replicaOf(ctx context.Context, pod *corev1.Pod, ma // along while updating other pods to be replicas func (dfi *DragonflyInstance) replicaOfNoOne(ctx context.Context, pod *corev1.Pod) error { redisClient := redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("%s:%d", pod.Status.PodIP, resources.DragonflyAdminPort), + Addr: net.JoinHostPort(pod.Status.PodIP, strconv.Itoa(resources.DragonflyAdminPort)), }) defer redisClient.Close()