Harden callGetPreferredAllocationIfAvailable() return value

Previously, we didn't check the contents of the result after calling out
to the plugin endpoint. This could have resulted in errors if the plugin
returned either 'nil' or an empty result. This patch fixes this.
This commit is contained in:
Kevin Klues 2020-07-04 12:33:01 +00:00
parent d87365494a
commit 67ecc11c44

View File

@ -997,8 +997,10 @@ func (m *ManagerImpl) callGetPreferredAllocationIfAvailable(podUID, contName, re
if err != nil {
return nil, fmt.Errorf("device plugin GetPreferredAllocation rpc failed with err: %v", err)
}
// TODO: Add metrics support for init RPC
return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil
if resp != nil && len(resp.ContainerResponses) > 0 {
return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil
}
return sets.NewString(), nil
}
// sanitizeNodeAllocatable scans through allocatedDevices in the device manager