From 68bb0935bdb785c84b006e5cf9a44a7af5e0d386 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Mon, 12 Sep 2022 11:42:40 +0300 Subject: [PATCH] devicemanager: do not leak empty TopologyInfo to TopologyManager Device Plugins that wish to leverage the Topology Manager can send back a populated TopologyInfo struct as part of the device registration, along with the device IDs and the health of the device. TopologyInfo is converted to TopologyHints and used by TopologyManager to find the optimal/desired resource allocation for a Pod. If a plugin sends an empty but non-nil instance of TopologyInfo for a resource, devicemanager passes it on as an empty instance of TopologyHint which is currently interpreted as "Hint Provider has no possible NUMA affinities for resource" which further means that pods requesting that resource will fail. To not block device resources that pass TopologyInfo{Nodes:[]*NUMANode{}} from being used, interprete that as nil set of hints and not a []TopologyHint{}. Signed-off-by: Mikko Ylinen --- pkg/kubelet/cm/devicemanager/topology_hints.go | 6 +++--- pkg/kubelet/cm/devicemanager/topology_hints_test.go | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/cm/devicemanager/topology_hints.go b/pkg/kubelet/cm/devicemanager/topology_hints.go index 4b094c7adbf..8e9521d8d12 100644 --- a/pkg/kubelet/cm/devicemanager/topology_hints.go +++ b/pkg/kubelet/cm/devicemanager/topology_hints.go @@ -137,9 +137,9 @@ func (m *ManagerImpl) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymana } func (m *ManagerImpl) deviceHasTopologyAlignment(resource string) bool { - // If any device has Topology set, we assume they care about alignment. - for device := range m.allDevices[resource] { - if m.allDevices[resource][device].Topology != nil { + // If any device has Topology NUMANodes available, we assume they care about alignment. + for _, device := range m.allDevices[resource] { + if device.Topology != nil && len(device.Topology.Nodes) > 0 { return true } } diff --git a/pkg/kubelet/cm/devicemanager/topology_hints_test.go b/pkg/kubelet/cm/devicemanager/topology_hints_test.go index cee5e48d51e..a7bc5157366 100644 --- a/pkg/kubelet/cm/devicemanager/topology_hints_test.go +++ b/pkg/kubelet/cm/devicemanager/topology_hints_test.go @@ -102,7 +102,7 @@ func TestGetTopologyHints(t *testing.T) { return tc.expectedHints[r][i].LessThan(tc.expectedHints[r][j]) }) if !reflect.DeepEqual(hints[r], tc.expectedHints[r]) { - t.Errorf("%v: Expected result to be %v, got %v", tc.description, tc.expectedHints[r], hints[r]) + t.Errorf("%v: Expected result to be %#v, got %#v", tc.description, tc.expectedHints[r], hints[r]) } } } @@ -1006,6 +1006,8 @@ func getCommonTestCases() []topologyHintTestCase { "testdevice": { {ID: "Dev1"}, {ID: "Dev2"}, + {ID: "Dev3", Topology: &pluginapi.TopologyInfo{Nodes: []*pluginapi.NUMANode{}}}, + {ID: "Dev4", Topology: &pluginapi.TopologyInfo{Nodes: nil}}, }, }, expectedHints: map[string][]topologymanager.TopologyHint{