Skip to content

Commit

Permalink
Merge pull request #362 from dvonthenen/checkancestors
Browse files Browse the repository at this point in the history
Add support for Resource Pool and Folder traversal for Zones/Regions
  • Loading branch information
k8s-ci-robot authored Jul 28, 2020
2 parents 21021a7 + 7b39b3e commit 857c124
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions pkg/cloudprovider/vsphere/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ func (z *zones) GetZoneByNodeName(ctx context.Context, nodeName k8stypes.NodeNam
klog.V(2).Info("zones.GetZoneByNodeName() NOT FOUND with ", string(nodeName))
return zone, ErrVMNotFound
}
klog.V(4).Infof("Getting zone/region for VM %s", node.NodeName)

vmHost, err := node.vm.HostSystem(ctx)
if err != nil {
klog.Errorf("Failed to get host system for VM: %q. err: %+v", node.vm.InventoryPath, err)
return zone, err
}
vmRP, err := node.vm.ResourcePool(ctx)
if err != nil {
klog.Warningf("Failed to get resource pool for VM: %q. err: %+v", node.vm.InventoryPath, err)
vmRP = nil
}

var oHost mo.HostSystem
err = vmHost.Properties(ctx, vmHost.Reference(), []string{"summary"}, &oHost)
Expand All @@ -118,8 +124,29 @@ func (z *zones) GetZoneByNodeName(ctx context.Context, nodeName k8stypes.NodeNam
}
klog.V(4).Infof("Host owning VM is %s", oHost.Summary.Config.Name)

// Look down the compute resources
zoneResult, err := z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, vmHost.Reference(), z.zone, z.region)
if err == nil {
zone.FailureDomain = zoneResult[cm.ZoneLabel]
zone.Region = zoneResult[cm.RegionLabel]
return zone, nil
}

// Look down the resource pools
if vmRP != nil {
zoneResult, err := z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, vmRP.Reference(), z.zone, z.region)
if err == nil {
zone.FailureDomain = zoneResult[cm.ZoneLabel]
zone.Region = zoneResult[cm.RegionLabel]
return zone, nil
}
}

// Look down the folders path
zoneResult, err = z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, node.vm.Reference(), z.zone, z.region)
if err != nil {
klog.Errorf("Failed to get host system properties. err: %+v", err)
return zone, err
Expand Down Expand Up @@ -147,12 +174,18 @@ func (z *zones) GetZoneByProviderID(ctx context.Context, providerID string) (clo
klog.V(2).Info("zones.GetZoneByProviderID() NOT FOUND with ", uid)
return zone, ErrVMNotFound
}
klog.V(4).Infof("Getting zone/region for VM %s", node.NodeName)

vmHost, err := node.vm.HostSystem(ctx)
if err != nil {
klog.Errorf("Failed to get host system for VM: %q. err: %+v", node.vm.InventoryPath, err)
return zone, err
}
vmRP, err := node.vm.ResourcePool(ctx)
if err != nil {
klog.Warningf("Failed to get resource pool for VM: %q. err: %+v", node.vm.InventoryPath, err)
vmRP = nil
}

var oHost mo.HostSystem
err = vmHost.Properties(ctx, vmHost.Reference(), []string{"summary"}, &oHost)
Expand All @@ -162,8 +195,29 @@ func (z *zones) GetZoneByProviderID(ctx context.Context, providerID string) (clo
}
klog.V(4).Infof("Host owning VM is %s", oHost.Summary.Config.Name)

// Look down the compute resources
zoneResult, err := z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, vmHost.Reference(), z.zone, z.region)
if err == nil {
zone.FailureDomain = zoneResult[cm.ZoneLabel]
zone.Region = zoneResult[cm.RegionLabel]
return zone, nil
}

// Look down the resource pools
if vmRP != nil {
zoneResult, err := z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, vmRP.Reference(), z.zone, z.region)
if err == nil {
zone.FailureDomain = zoneResult[cm.ZoneLabel]
zone.Region = zoneResult[cm.RegionLabel]
return zone, nil
}
}

// Look down the folders path
zoneResult, err = z.nodeManager.connectionManager.LookupZoneByMoref(
ctx, node.tenantRef, node.vm.Reference(), z.zone, z.region)
if err != nil {
klog.Errorf("Failed to get host system properties. err: %+v", err)
return zone, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/connectionmanager/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (cm *ConnectionManager) LookupZoneByMoref(ctx context.Context, tenantRef st
tags, err := client.ListAttachedTags(ctx, obj)
if err != nil {
klog.Errorf("Cannot list attached tags. Err: %v", err)
return err
continue
}
for _, value := range tags {
tag, err := client.GetTag(ctx, value)
Expand Down

0 comments on commit 857c124

Please sign in to comment.