@@ -20,6 +20,7 @@ import (
20
20
"k8s.io/api/core/v1"
21
21
"k8s.io/apimachinery/pkg/util/sets"
22
22
"k8s.io/klog/v2"
23
+ pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
23
24
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
24
25
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
25
26
)
@@ -103,14 +104,8 @@ func (m *ManagerImpl) generateDeviceTopologyHints(resource string, devices sets.
103
104
// First, update minAffinitySize for the current request size.
104
105
devicesInMask := 0
105
106
for _ , device := range m .allDevices [resource ] {
106
- if device .Topology == nil {
107
- continue
108
- }
109
- for _ , node := range device .Topology .Nodes {
110
- if mask .IsSet (int (node .ID )) {
111
- devicesInMask ++
112
- break
113
- }
107
+ if mask .AnySet (m .getNUMANodeIds (device .Topology )) {
108
+ devicesInMask ++
114
109
}
115
110
}
116
111
if devicesInMask >= request && mask .Count () < minAffinitySize {
@@ -121,14 +116,8 @@ func (m *ManagerImpl) generateDeviceTopologyHints(resource string, devices sets.
121
116
// NUMA Node combination to satisfy the device request.
122
117
numMatching := 0
123
118
for d := range devices {
124
- if m.allDevices [resource ][d ].Topology == nil {
125
- continue
126
- }
127
- for _ , node := range m.allDevices [resource ][d ].Topology .Nodes {
128
- if mask .IsSet (int (node .ID )) {
129
- numMatching ++
130
- break
131
- }
119
+ if mask .AnySet (m .getNUMANodeIds (m.allDevices [resource ][d ].Topology )) {
120
+ numMatching ++
132
121
}
133
122
}
134
123
@@ -158,3 +147,14 @@ func (m *ManagerImpl) generateDeviceTopologyHints(resource string, devices sets.
158
147
159
148
return hints
160
149
}
150
+
151
+ func (m * ManagerImpl ) getNUMANodeIds (topology * pluginapi.TopologyInfo ) []int {
152
+ if topology == nil {
153
+ return nil
154
+ }
155
+ var ids []int
156
+ for _ , n := range topology .Nodes {
157
+ ids = append (ids , int (n .ID ))
158
+ }
159
+ return ids
160
+ }
0 commit comments