From de60740d67465974501d00664eeb386408f5d96a Mon Sep 17 00:00:00 2001 From: Alexander Trost Date: Wed, 7 Mar 2018 17:36:30 +0100 Subject: [PATCH] Fix assignment of node address to mon in failover Signed-off-by: Alexander Trost --- pkg/operator/cluster/ceph/mon/health.go | 16 +++++++++++----- pkg/operator/cluster/ceph/mon/mon.go | 2 +- pkg/operator/cluster/ceph/mon/mon_test.go | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/operator/cluster/ceph/mon/health.go b/pkg/operator/cluster/ceph/mon/health.go index e38232cdb..92af02c12 100644 --- a/pkg/operator/cluster/ceph/mon/health.go +++ b/pkg/operator/cluster/ceph/mon/health.go @@ -230,11 +230,6 @@ func (c *Cluster) failoverMon(name string) error { return fmt.Errorf("failed to create mon service. %+v", err) } - if !c.HostNetwork { - m.PublicIP = serviceIP - c.clusterInfo.Monitors[m.Name] = mon.ToCephMon(m.Name, m.PublicIP, m.Port) - } - mConf := []*monConfig{m} // Assign the pod to a node @@ -242,6 +237,17 @@ func (c *Cluster) failoverMon(name string) error { return fmt.Errorf("failed to assign pods to mons. %+v", err) } + if c.HostNetwork { + node, ok := c.mapping.Node[m.Name] + if !ok { + return fmt.Errorf("mon %s doesn't exist in assignment map", m.Name) + } + m.PublicIP = node.Address + } else { + m.PublicIP = serviceIP + } + c.clusterInfo.Monitors[m.Name] = mon.ToCephMon(m.Name, m.PublicIP, m.Port) + // Start the pod if err = c.startPods(mConf); err != nil { return fmt.Errorf("failed to start new mon %s. %+v", m.Name, err) diff --git a/pkg/operator/cluster/ceph/mon/mon.go b/pkg/operator/cluster/ceph/mon/mon.go index c6e503db3..220907b51 100644 --- a/pkg/operator/cluster/ceph/mon/mon.go +++ b/pkg/operator/cluster/ceph/mon/mon.go @@ -224,7 +224,7 @@ func (c *Cluster) initMonIPs(mons []*monConfig) error { logger.Infof("setting mon endpoints for hostnetwork mode") node, ok := c.mapping.Node[m.Name] if !ok { - return fmt.Errorf("mon doesn't exit in assignment map") + return fmt.Errorf("mon doesn't exist in assignment map") } m.PublicIP = node.Address } else { diff --git a/pkg/operator/cluster/ceph/mon/mon_test.go b/pkg/operator/cluster/ceph/mon/mon_test.go index 2fe5eefd5..4eec4eeb6 100644 --- a/pkg/operator/cluster/ceph/mon/mon_test.go +++ b/pkg/operator/cluster/ceph/mon/mon_test.go @@ -60,7 +60,7 @@ func newTestStartCluster(namespace string) *clusterd.Context { func newCluster(context *clusterd.Context, namespace string, hostNetwork bool, resources v1.ResourceRequirements) *Cluster { return &Cluster{ - HostNetwork: true, + HostNetwork: hostNetwork, context: context, Namespace: namespace, Version: "myversion",