forked from rook/rook
ceph: osds to always use hostname for node selector
The node selector for running OSDs on PVCs was using the node name rather than the node's hostname. In clusters where the node name is different from the hostname this would cause the osd daemons to be in pending state indefinitely. Now the node selector will use the hostname as expected. Signed-off-by: travisn <tnielsen@redhat.com>
This commit is contained in:
@@ -765,7 +765,12 @@ func (c *Cluster) getPVCHostName(pvcName string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
for _, pod := range podList.Items {
|
||||
return pod.Spec.NodeName, nil
|
||||
name, err := k8sutil.GetNodeHostName(c.context.Clientset, pod.Spec.NodeName)
|
||||
if err != nil {
|
||||
logger.Warningf("falling back to node name %s since hostname not found for node", pod.Spec.NodeName)
|
||||
name = pod.Spec.NodeName
|
||||
}
|
||||
return name, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -108,6 +108,19 @@ func GetNodeNameFromHostname(clientset kubernetes.Interface, hostName string) (s
|
||||
return hostName, fmt.Errorf("node not found")
|
||||
}
|
||||
|
||||
// GetNodeHostName returns the hostname label given the node name.
|
||||
func GetNodeHostName(clientset kubernetes.Interface, nodeName string) (string, error) {
|
||||
node, err := clientset.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
hostname, ok := node.Labels[v1.LabelHostname]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("hostname not found on the node")
|
||||
}
|
||||
return hostname, nil
|
||||
}
|
||||
|
||||
// GetNodeHostNames returns the name of the node resource mapped to their hostname label.
|
||||
// Typically these will be the same name, but sometimes they are not such as when nodes have a longer
|
||||
// dns name, but the hostname is short.
|
||||
|
||||
Reference in New Issue
Block a user