Skip to content

Commit

Permalink
Merge pull request #640 from travisn/backport-disable-msgr1
Browse files Browse the repository at this point in the history
Bug 2262134: mon: Disable v1 port if msgr2 is required
  • Loading branch information
travisn authored May 1, 2024
2 parents 7a53ffd + a629382 commit 4f297e0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/operator/ceph/cluster/mon/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,12 @@ func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) corev1.Container
WorkingDir: config.VarLogCephDir,
}

if monConfig.Port != DefaultMsgr2Port {
bindaddr := controller.ContainerEnvVarReference(podIPEnvVar)
if monConfig.Port == DefaultMsgr2Port {
container.Args = append(container.Args, config.NewFlag("ms_bind_msgr1", "false"))
// To avoid binding to the msgr1 port, ceph expects to find the msgr2 port on the bind address
bindaddr = fmt.Sprintf("%s:%d", bindaddr, DefaultMsgr2Port)
} else {
// Add messenger 1 port
container.Ports = append(container.Ports, corev1.ContainerPort{
Name: "tcp-msgr1",
Expand All @@ -349,8 +354,7 @@ func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) corev1.Container
if !monConfig.UseHostNetwork {
// Opposite of the above, --public-bind-addr will *not* still advertise on the previous
// port, which makes sense because this is the pod IP, which changes with every new pod.
container.Args = append(container.Args,
config.NewFlag("public-bind-addr", controller.ContainerEnvVarReference(podIPEnvVar)))
container.Args = append(container.Args, config.NewFlag("public-bind-addr", bindaddr))
}

return container
Expand Down
26 changes: 26 additions & 0 deletions pkg/operator/ceph/cluster/mon/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ func testPodSpec(t *testing.T, monID string, pvc bool) {
assert.Equal(t, int32(900), container.LivenessProbe.InitialDelaySeconds)
assert.Equal(t, int32(1000), container.StartupProbe.InitialDelaySeconds)
})

t.Run(("msgr2 not required"), func(t *testing.T) {
container := c.makeMonDaemonContainer(monConfig)
checkMsgr2Required(t, container, false)
})

t.Run(("require msgr2"), func(t *testing.T) {
monConfig.Port = DefaultMsgr2Port
container := c.makeMonDaemonContainer(monConfig)
checkMsgr2Required(t, container, true)
})
}

func checkMsgr2Required(t *testing.T, container v1.Container, expectedRequireMsgr2 bool) {
foundDisabledMsgr1 := false
foundMsgr2Port := false
for _, arg := range container.Args {
if arg == "--ms-bind-msgr1=false" {
foundDisabledMsgr1 = true
}
if arg == "--public-bind-addr=$(ROOK_POD_IP):3300" {
foundMsgr2Port = true
}
}
assert.Equal(t, expectedRequireMsgr2, foundDisabledMsgr1)
assert.Equal(t, expectedRequireMsgr2, foundMsgr2Port)
}

func TestDeploymentPVCSpec(t *testing.T) {
Expand Down

0 comments on commit 4f297e0

Please sign in to comment.