Skip to content

Commit

Permalink
Merge pull request #462 from dpengla/fix_release-1.18
Browse files Browse the repository at this point in the history
cherry pick from release 1.18
  • Loading branch information
k8s-ci-robot authored May 25, 2021
2 parents 9ce6ca6 + b614618 commit 1fcb0ed
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cloudprovider/vsphere/nodemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ func (nm *NodeManager) DiscoverNode(nodeID string, searchBy cm.FindVM) error {
break
}
}
}

if len(oVM.Guest.Net) > 0 {
if !foundInternal && !foundExternal {
return fmt.Errorf("unable to find suitable IP address for node %s with IP family %s", nodeID, ipFamily)
}
Expand Down
66 changes: 66 additions & 0 deletions pkg/cloudprovider/vsphere/nodemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,72 @@ func TestDiscoverNodeByName(t *testing.T) {
}
}

func TestDiscoverNodeWithMultiIFByName(t *testing.T) {
cfg, ok := configFromEnvOrSim(true)
defer ok()

connMgr := cm.NewConnectionManager(cfg, nil, nil)
defer connMgr.Logout()

nm := newNodeManager(nil, connMgr)

vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
vm.Guest.HostName = strings.ToLower(vm.Name) // simulator.SearchIndex.FindByDnsName matches against the guest.hostName property
expectedIP := "10.10.108.12"
vm.Guest.Net = []vimtypes.GuestNicInfo{
{
Network: "test_k8s_tenant_c123",
IpAddress: []string{
"fe80::250:56ff:fe89:d2c7",
},
},
{
Network: "test_k8s_tenant_c123",
IpAddress: []string{
expectedIP,
"10.10.108.10",
"fe80::250:56ff:fe89:d2c7",
},
},
}
name := vm.Name

err := connMgr.Connect(context.Background(), connMgr.VsphereInstanceMap[cfg.Global.VCenterIP])
if err != nil {
t.Errorf("Failed to Connect to vSphere: %s", err)
}

err = nm.DiscoverNode(name, cm.FindVMByName)
if err != nil {
t.Errorf("Failed DiscoverNode: %s", err)
}

if len(nm.nodeNameMap) != 1 {
t.Errorf("Failed: nodeNameMap should be a length of 1")
}

if len(nm.nodeUUIDMap) != 1 {
t.Errorf("Failed: nodeUUIDMap should be a length of 1")
}

if nodeInfo, ok := nm.nodeNameMap[strings.ToLower(name)]; ok {
for _, adr := range nodeInfo.NodeAddresses {
if adr.Type == "InternalIP" {
if adr.Address != expectedIP {
t.Errorf("failed: InternalIP should be %v, not %v.", expectedIP, adr.Address)
}
}
if adr.Type == "ExternalIP" {
if adr.Address != expectedIP {
t.Errorf("failed: InternalIP should be %v, not %v.", expectedIP, adr.Address)
}
}
}
} else {
t.Errorf("failed: %v not found", name)
}
}

func TestExport(t *testing.T) {
cfg, ok := configFromEnvOrSim(true)
defer ok()
Expand Down

0 comments on commit 1fcb0ed

Please sign in to comment.