From e13bdd0f8f92a79ff783961ee32a1a6bde9663a7 Mon Sep 17 00:00:00 2001 From: travisn Date: Tue, 28 Mar 2023 15:11:36 -0600 Subject: [PATCH] csi: ipv6 compatibility for requiring msgr2 The msgr2 conversion assumed the endpoints were formatted with a single :, which is not compatible with ipv6. Now if the endpoint ends with the v1 port, it will simply update the prefix to v2. Signed-off-by: travisn (cherry picked from commit bbfba5425fb332529c6050a11ba4b3b20c391ad0) --- pkg/operator/ceph/csi/cluster_config.go | 11 ++++------- pkg/operator/ceph/csi/cluster_config_test.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/operator/ceph/csi/cluster_config.go b/pkg/operator/ceph/csi/cluster_config.go index 043b094e6..a9d62aa0e 100644 --- a/pkg/operator/ceph/csi/cluster_config.go +++ b/pkg/operator/ceph/csi/cluster_config.go @@ -108,13 +108,10 @@ func MonEndpoints(mons map[string]*cephclient.MonInfo, requireMsgr2 bool) []stri endpoint := m.Endpoint if requireMsgr2 { logger.Debugf("evaluating mon %q for msgr1 on endpoint %q", m.Name, m.Endpoint) - if strings.HasSuffix(m.Endpoint, fmt.Sprintf(":%d", client.Msgr1port)) { - parts := strings.Split(m.Endpoint, ":") - if len(parts) != 2 { - logger.Errorf("endpoint %q does not contain two parts to extract the port", m.Endpoint) - continue - } - endpoint = fmt.Sprintf("%s:%d", parts[0], client.Msgr2port) + msgr1Suffix := fmt.Sprintf(":%d", client.Msgr1port) + if strings.HasSuffix(m.Endpoint, msgr1Suffix) { + address := m.Endpoint[0:strings.LastIndex(m.Endpoint, msgr1Suffix)] + endpoint = fmt.Sprintf("%s:%d", address, client.Msgr2port) logger.Debugf("mon %q will use the msgrv2 port: %q", m.Name, endpoint) } } diff --git a/pkg/operator/ceph/csi/cluster_config_test.go b/pkg/operator/ceph/csi/cluster_config_test.go index dc64ed60f..5f778a16d 100644 --- a/pkg/operator/ceph/csi/cluster_config_test.go +++ b/pkg/operator/ceph/csi/cluster_config_test.go @@ -369,15 +369,20 @@ func TestMonEndpoints(t *testing.T) { verifyEndpointPort(t, endpoints, "3300") }) - t.Run("bad endpoint", func(t *testing.T) { + t.Run("ipv6 endpoint conversion", func(t *testing.T) { monInfo := map[string]*cephclient.MonInfo{ - "a": {Name: "a", Endpoint: "1.2.3.4:5:6789"}, - "b": {Name: "b", Endpoint: "1.2.3.5:6789"}, - "c": {Name: "c", Endpoint: "1.2.3.6:6789"}, + "a": {Name: "a", Endpoint: "[fd07:aaaa:bbbb:cccc::11]:6789"}, + "b": {Name: "a", Endpoint: "[1234:6789:bbbb:cccc::11]:6789"}, } endpoints := MonEndpoints(monInfo, true) assert.Equal(t, 2, len(endpoints)) verifyEndpointPort(t, endpoints, "3300") + for _, endpoint := range endpoints { + // Verify that the v1 port inside the ipv6 address will not be replaced + if strings.HasPrefix(endpoint, "[1234") { + assert.True(t, strings.HasPrefix(endpoint, "[1234:6789")) + } + } }) }