From 46cdf15936103d0fefe25f997582e619efc74ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Mon, 24 Jun 2019 16:19:33 +0200 Subject: [PATCH] ceph: config: apply the correct msgr2 prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit External clusters might only listen on msgr2, so we must acknowledge that and set the correct prefix to 'v2:' instead of 'v1:' on the operator's ceph config file. Signed-off-by: Sébastien Han --- pkg/daemon/ceph/config/config.go | 17 +++++++++++++++-- pkg/daemon/ceph/config/config_test.go | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/daemon/ceph/config/config.go b/pkg/daemon/ceph/config/config.go index 0200bee73..047bb0a07 100644 --- a/pkg/daemon/ceph/config/config.go +++ b/pkg/daemon/ceph/config/config.go @@ -43,7 +43,9 @@ const ( // DefaultKeyringFile is the default name of the file where Ceph stores its keyring info DefaultKeyringFile = "keyring" // Msgr2port is the listening port of the messenger v2 protocol - Msgr2port = 3300 + Msgr2port = 3300 + msgr1Prefix = "v1:" + msgr2Prefix = "v2:" ) // GlobalConfig represents the [global] sections of Ceph's config file. @@ -225,7 +227,8 @@ func CreateDefaultCephConfig(context *clusterd.Context, cluster *ClusterInfo, ru } else if podName != "" && strings.Contains(podName, "operator") { // This is an operator and its version is always based on Nautilus // so it knows how to parse both msgr1 and msgr2 syntax - monHosts[i] = "v1:" + msgr1Endpoint + prefix := msgrPrefix(currentMonPort) + monHosts[i] = prefix + msgr1Endpoint } else { // This is not the operator, it's an OSD and its Ceph version is before Nautilus monHosts[i] = msgr1Endpoint @@ -339,3 +342,13 @@ func logLevelToCephLogLevel(logLevel capnslog.LogLevel) int { return 0 } + +func msgrPrefix(currentMonPort int32) string { + // Some installation might only be listening on v2, so let's set the prefix accordingly + if currentMonPort == Msgr2port { + return msgr2Prefix + } + + return msgr1Prefix + +} diff --git a/pkg/daemon/ceph/config/config_test.go b/pkg/daemon/ceph/config/config_test.go index 083972d68..0288b6200 100644 --- a/pkg/daemon/ceph/config/config_test.go +++ b/pkg/daemon/ceph/config/config_test.go @@ -178,3 +178,14 @@ func verifyConfigValue(t *testing.T, actualConf *ini.File, section, key, expecte actualVal := k.Value() assert.Equal(t, expectedVal, actualVal) } + +func TestOperatorEndpoint(t *testing.T) { + var fakeCurrentMonPort int32 + fakeCurrentMonPort = 3300 + prefix := msgrPrefix(fakeCurrentMonPort) + assert.Equal(t, "v2:", prefix) + + fakeCurrentMonPort = 6789 + prefix = msgrPrefix(fakeCurrentMonPort) + assert.Equal(t, "v1:", prefix) +}