From 44253bcfd43d5c04a46b3db3f8a6ff29d581650e Mon Sep 17 00:00:00 2001 From: Roberto Bonafiglia Date: Wed, 23 Mar 2022 15:35:51 +0100 Subject: [PATCH] Fixed etcd URL in case of IPv6 address Signed-off-by: Roberto Bonafiglia --- pkg/etcd/etcd.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 2e623ef0a5..8710c0cca2 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -45,6 +45,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/util/retry" + utilsnet "k8s.io/utils/net" ) const ( @@ -744,11 +745,17 @@ func (e *ETCD) migrateFromSQLite(ctx context.Context) error { // peerURL returns the peer access address for the local node func (e *ETCD) peerURL() string { + if utilsnet.IsIPv6String(e.address) { + return fmt.Sprintf("https://[%s]:2380", e.address) + } return fmt.Sprintf("https://%s:2380", e.address) } // clientURL returns the client access address for the local node func (e *ETCD) clientURL() string { + if utilsnet.IsIPv6String(e.address) { + return fmt.Sprintf("https://[%s]:2379", e.address) + } return fmt.Sprintf("https://%s:2379", e.address) } @@ -756,7 +763,11 @@ func (e *ETCD) clientURL() string { func (e *ETCD) metricsURL(expose bool) string { address := "http://127.0.0.1:2381" if expose { - address = fmt.Sprintf("http://%s:2381,%s", e.address, address) + if utilsnet.IsIPv6String(e.address) { + address = fmt.Sprintf("https://[%s]:2381,%s", e.address, address) + } else { + address = fmt.Sprintf("https://%s:2381,%s", e.address, address) + } } return address }