Skip to content

Commit 061afa5

Browse files
author
Dmitry Rozhkov
authored
Merge pull request #291 from bart0sh/PR0073-copy-topology-module
Copy topology module
2 parents 96ed47d + 1bbcbc6 commit 061afa5

File tree

21 files changed

+705
-50
lines changed

21 files changed

+705
-50
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/go-ini/ini v1.46.0
88
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
99
github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750
10-
github.com/intel/cri-resource-manager/pkg/topology v0.0.0-20200207111533-82d10bdaca4e
1110
github.com/pkg/errors v0.8.1
1211
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
1312
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
281281
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
282282
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
283283
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
284-
github.com/intel/cri-resource-manager/pkg/topology v0.0.0-20200207111533-82d10bdaca4e h1:+pD7vYnhjGklatQ/Zs98yB/l6ETL+79WiI3IGM9Bmqk=
285-
github.com/intel/cri-resource-manager/pkg/topology v0.0.0-20200207111533-82d10bdaca4e/go.mod h1:98ghzNsdMHeewnXWSFGx+Sf1AbZEVcL+mOLvE6DI4OQ=
286284
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
287285
github.com/jimstudt/http-authentication v0.0.0-20140401203705-3eca13d6893a/go.mod h1:wK6yTYYcgjHE1Z1QtXACPDjcFJyBskHEdagmnq3vsP8=
288286
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=

pkg/deviceplugin/api.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
package deviceplugin
1616

1717
import (
18-
"sort"
19-
"strconv"
20-
"strings"
21-
22-
"github.com/pkg/errors"
23-
24-
"github.com/intel/cri-resource-manager/pkg/topology"
18+
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/topology"
2519
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
2620
)
2721

@@ -34,45 +28,6 @@ type DeviceInfo struct {
3428
topology *pluginapi.TopologyInfo
3529
}
3630

37-
// getTopologyInfo returns topology information for the list of device nodes
38-
func getTopologyInfo(devs []string) (*pluginapi.TopologyInfo, error) {
39-
var result pluginapi.TopologyInfo
40-
nodeIDs := map[int64]struct{}{}
41-
for _, dev := range devs {
42-
sysfsDevice, err := topology.FindSysFsDevice(dev)
43-
if err != nil {
44-
return nil, err
45-
}
46-
47-
if sysfsDevice == "" {
48-
return nil, errors.Errorf("device %s doesn't exist", dev)
49-
}
50-
51-
hints, err := topology.NewTopologyHints(sysfsDevice)
52-
if err != nil {
53-
return nil, err
54-
}
55-
56-
for _, hint := range hints {
57-
for _, nNode := range strings.Split(hint.NUMAs, ",") {
58-
nNodeID, err := strconv.ParseInt(strings.TrimSpace(nNode), 10, 64)
59-
if err != nil {
60-
return nil, errors.Wrapf(err, "unable to convert numa node %s into int64", nNode)
61-
}
62-
if nNodeID < 0 {
63-
return nil, errors.Wrapf(err, "numa node is negative: %d", nNodeID)
64-
}
65-
if _, ok := nodeIDs[nNodeID]; !ok {
66-
result.Nodes = append(result.Nodes, &pluginapi.NUMANode{ID: nNodeID})
67-
nodeIDs[nNodeID] = struct{}{}
68-
}
69-
}
70-
}
71-
}
72-
sort.Slice(result.Nodes, func(i, j int) bool { return result.Nodes[i].ID < result.Nodes[j].ID })
73-
return &result, nil
74-
}
75-
7631
// NewDeviceInfo makes DeviceInfo struct and adds topology information to it
7732
func NewDeviceInfo(state string, nodes []pluginapi.DeviceSpec, mounts []pluginapi.Mount, envs map[string]string) DeviceInfo {
7833
deviceInfo := DeviceInfo{
@@ -86,7 +41,7 @@ func NewDeviceInfo(state string, nodes []pluginapi.DeviceSpec, mounts []pluginap
8641
devPaths = append(devPaths, node.HostPath)
8742
}
8843

89-
topologyInfo, err := getTopologyInfo(devPaths)
44+
topologyInfo, err := topology.GetTopologyInfo(devPaths)
9045
if err == nil {
9146
deviceInfo.topology = topologyInfo
9247
}

pkg/topology/testdata/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is a kludge to work around the golang toolchain not being able
2+
// to handle packages with any files with a colon (:) in their name,
3+
// even if those are not golang sources.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0x030000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0x5912
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
226:1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
226:129
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0-7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ff
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0x8086
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0-7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,2,3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0-7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0-7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4,5,6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../devices/pci0000:00/0000:00:02.0/

0 commit comments

Comments
 (0)