Skip to content

Commit 67ecc11

Browse files
committed
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.
1 parent d873654 commit 67ecc11

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/kubelet/cm/devicemanager/manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,10 @@ func (m *ManagerImpl) callGetPreferredAllocationIfAvailable(podUID, contName, re
997997
if err != nil {
998998
return nil, fmt.Errorf("device plugin GetPreferredAllocation rpc failed with err: %v", err)
999999
}
1000-
// TODO: Add metrics support for init RPC
1001-
return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil
1000+
if resp != nil && len(resp.ContainerResponses) > 0 {
1001+
return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil
1002+
}
1003+
return sets.NewString(), nil
10021004
}
10031005

10041006
// sanitizeNodeAllocatable scans through allocatedDevices in the device manager

0 commit comments

Comments
 (0)