Skip to content

Commit

Permalink
[bugfix] avoid panic when host cache is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tbelda-ems committed Sep 23, 2023
1 parent a25130a commit 795cbd1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/vccollector/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,13 @@ func (c *VcCollector) getHostObjectFromReference(
dcindex int,
r *types.ManagedObjectReference,
) *object.HostSystem {
if len(c.hosts) < dcindex || r == nil {
return nil
}
for _, host := range c.hosts[dcindex] {
if host == nil {
continue
}
if host.Reference().Type == r.Type && host.Reference().Value == r.Value {
return host
}
Expand Down

0 comments on commit 795cbd1

Please sign in to comment.