From 496c64055f7d89917e8fc6d953c80c52fb09a5f5 Mon Sep 17 00:00:00 2001 From: razo7 Date: Mon, 12 Jun 2023 15:31:32 +0300 Subject: [PATCH] Check if Mahchine has node Without it we might get a nil pointer exception --- test/e2e/utils/cluster.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/e2e/utils/cluster.go b/test/e2e/utils/cluster.go index 84f7c2df..5641c8aa 100644 --- a/test/e2e/utils/cluster.go +++ b/test/e2e/utils/cluster.go @@ -58,8 +58,17 @@ func GetAWSNodeInfoList(machineClient *machineclient.MachineV1beta1Client) (map[ return nodeList, err } + var missNodeMachineErr error // creates map for nodeName and AWS instance ID for _, machine := range machineList.Items { + if machine.Status.NodeRef == nil || machine.Spec.ProviderID == nil { + if missNodeMachineErr != nil { + missNodeMachineErr = fmt.Errorf("machine %s is not associated with any node or it't provider ID is missing\n%w", string(machine.Spec.Name), missNodeMachineErr) + } else { + missNodeMachineErr = fmt.Errorf("machine %s is not associated with any node or it't provider ID is missing", string(machine.Spec.Name)) + } + continue + } nodeName := v1alpha1.NodeName(string(machine.Status.NodeRef.Name)) providerID := string(*machine.Spec.ProviderID) @@ -69,7 +78,7 @@ func GetAWSNodeInfoList(machineClient *machineclient.MachineV1beta1Client) (map[ nodeList[nodeName] = instanceID fmt.Printf("node: %s Instance ID: %s \n", nodeName, instanceID) } - return nodeList, nil + return nodeList, missNodeMachineErr } // GetBMHNodeInfoList returns a list of the node names and their identification, e.g., ports