Skip to content

Commit e1d6dd1

Browse files
code cleanup
1 parent 23b178f commit e1d6dd1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pkg/helpers/helpers.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,24 @@ func GetNodesForPool(mcpLister v1.MachineConfigPoolLister, nodeLister corev1list
5555
// temporarily be set to `unknown`. Once the node exists (is not nil) and the annotations are properly set,
5656
// the node will update again and the pool name will be updated.
5757
func GetPrimaryPoolNameForMCN(mcpLister v1.MachineConfigPoolLister, node *corev1.Node) (string, error) {
58+
// Handle case of nil node
5859
if node == nil {
5960
klog.Error("node object is nil, setting associated MCP to unknown")
6061
return "unknown", nil
61-
} else {
62-
primaryPool, err := GetPrimaryPoolForNode(mcpLister, node)
63-
if err != nil {
64-
klog.Errorf("error getting primary pool for node: %v", node.Name)
65-
return "", err
66-
} else if primaryPool == nil {
67-
// On first provisioning, the node may not have annoatations and, thus, will not be associated with a pool
68-
klog.Infof("No primary pool is associated with node: %v", node.Name)
69-
return "unknown", nil
70-
} else {
71-
return primaryPool.Name, nil
72-
}
7362
}
63+
64+
// Use `GetPrimaryPoolForNode` to get primary MCP associated with node
65+
primaryPool, err := GetPrimaryPoolForNode(mcpLister, node)
66+
if err != nil {
67+
klog.Errorf("error getting primary pool for node: %v", node.Name)
68+
return "", err
69+
} else if primaryPool == nil {
70+
// On first provisioning, the node may not have annoatations and, thus, will not be associated with a pool.
71+
// In this case, the pool value will be set to a temporary dummy value.
72+
klog.Infof("No primary pool is associated with node: %v", node.Name)
73+
return "unknown", nil
74+
}
75+
return primaryPool.Name, nil
7476
}
7577

7678
func GetPrimaryPoolForNode(mcpLister v1.MachineConfigPoolLister, node *corev1.Node) (*mcfgv1.MachineConfigPool, error) {

0 commit comments

Comments
 (0)