From 3068f6108fb8d9a5e3ca768cde6cef1e016a4082 Mon Sep 17 00:00:00 2001 From: Hans Rakers Date: Thu, 4 May 2023 15:49:18 +0200 Subject: [PATCH] Strip domain from node.Name before matching with vm names Signed-off-by: Hans Rakers --- cloudstack_loadbalancer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cloudstack_loadbalancer.go b/cloudstack_loadbalancer.go index d5793be9..2e9dd73d 100644 --- a/cloudstack_loadbalancer.go +++ b/cloudstack_loadbalancer.go @@ -332,7 +332,9 @@ func (cs *CSCloud) getLoadBalancer(service *corev1.Service) (*loadBalancer, erro func (cs *CSCloud) verifyHosts(nodes []*corev1.Node) ([]string, string, error) { hostNames := map[string]bool{} for _, node := range nodes { - hostNames[strings.ToLower(node.Name)] = true + // node.Name can be an FQDN as well, and CloudStack VM names aren't + // To match, we need to Split the domain part off here, if present + hostNames[strings.Split(strings.ToLower(node.Name), ".")[0]] = true } p := cs.client.VirtualMachine.NewListVirtualMachinesParams() @@ -362,6 +364,10 @@ func (cs *CSCloud) verifyHosts(nodes []*corev1.Node) ([]string, string, error) { } } + if len(hostIDs) == 0 || len(networkID) == 0 { + return nil, "", fmt.Errorf("none of the hosts matched the list of VMs retrieved from CS API") + } + return hostIDs, networkID, nil }