ceph: preserve the non-default port for hostnetworking
Clusters using host networking will not work if the non-default port is being used by the mons. Previous to rook 1.0 the mons were all using the non-default port 6790 and now they are using the default port of 6789 from 1.0. Now host networking will preserve the non-default port to allow upgrades to continue working. Signed-off-by: travisn <tnielsen@redhat.com>
This commit is contained in:
2 files changed
+40
-4
No files matched your search
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package mon
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
@@ -271,11 +272,36 @@ func TestHostNetwork(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(nodes))
|
||||
|
||||
pod := c.makeMonPod(testGenMonConfig("c"), nodes[2].Name)
|
||||
monConfig := testGenMonConfig("c")
|
||||
pod := c.makeMonPod(monConfig, nodes[2].Name)
|
||||
assert.NotNil(t, pod)
|
||||
|
||||
assert.Equal(t, true, pod.Spec.HostNetwork)
|
||||
assert.Equal(t, v1.DNSClusterFirstWithHostNet, pod.Spec.DNSPolicy)
|
||||
val, message := extractArgValue(pod.Spec.Containers[0].Args, "--public-addr")
|
||||
assert.Equal(t, "2.4.6.3", val, message)
|
||||
val, message = extractArgValue(pod.Spec.Containers[0].Args, "--public-bind-addr")
|
||||
assert.Equal(t, "$(ROOK_POD_IP)", val, message)
|
||||
|
||||
monConfig.Port = 6790
|
||||
pod = c.makeMonPod(monConfig, nodes[2].Name)
|
||||
val, message = extractArgValue(pod.Spec.Containers[0].Args, "--public-addr")
|
||||
assert.Equal(t, "2.4.6.3:6790", val, message)
|
||||
val, message = extractArgValue(pod.Spec.Containers[0].Args, "--public-bind-addr")
|
||||
assert.Equal(t, "$(ROOK_POD_IP):6790", val, message)
|
||||
assert.NotNil(t, pod)
|
||||
}
|
||||
|
||||
func extractArgValue(args []string, name string) (string, string) {
|
||||
for _, arg := range args {
|
||||
if strings.Contains(arg, name) {
|
||||
vals := strings.Split(arg, "=")
|
||||
if len(vals) != 2 {
|
||||
return "", "cannot split arg: " + arg
|
||||
}
|
||||
return vals[1], "value: " + vals[1]
|
||||
}
|
||||
}
|
||||
return "", "arg not found: " + name
|
||||
}
|
||||
|
||||
func TestGetNodeInfoFromNode(t *testing.T) {
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package mon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
@@ -158,6 +159,15 @@ func (c *Cluster) makeMonFSInitContainer(monConfig *monConfig) v1.Container {
|
||||
|
||||
func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) v1.Container {
|
||||
podIPEnvVar := "ROOK_POD_IP"
|
||||
publicAddr := monConfig.PublicIP
|
||||
publicBindAddr := opspec.ContainerEnvVarReference(podIPEnvVar)
|
||||
if c.HostNetwork && monConfig.Port != DefaultMsgr1Port {
|
||||
logger.Warningf("Starting mon %s with host networking on a non-default port %d. The mon must be failed over before enabling msgr2.",
|
||||
monConfig.DaemonName, monConfig.Port)
|
||||
publicAddr = fmt.Sprintf("%s:%d", publicAddr, monConfig.Port)
|
||||
publicBindAddr = fmt.Sprintf("%s:%d", publicBindAddr, monConfig.Port)
|
||||
}
|
||||
|
||||
container := v1.Container{
|
||||
Name: "mon",
|
||||
Command: []string{
|
||||
@@ -168,10 +178,10 @@ func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) v1.Container {
|
||||
"--foreground",
|
||||
// If the mon is already in the monmap, when the port is left off of --public-addr,
|
||||
// it will still advertise on the previous port b/c monmap is saved to mon database.
|
||||
config.NewFlag("public-addr", monConfig.PublicIP),
|
||||
config.NewFlag("public-addr", publicAddr),
|
||||
// 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.
|
||||
config.NewFlag("public-bind-addr", opspec.ContainerEnvVarReference(podIPEnvVar)),
|
||||
config.NewFlag("public-bind-addr", publicBindAddr),
|
||||
),
|
||||
Image: c.spec.CephVersion.Image,
|
||||
VolumeMounts: opspec.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName),
|
||||
|
||||
Reference in new issue
Block a user