Skip to content

Commit 8d9a4cd

Browse files
committed
nrt: deps: bump to noderesourcetopology API v0.1.2
Bump NRT API package to v0.1.2; there is no API change, but we have now a better replacement for the internal `getID` helper, which we can now remove. Signed-off-by: Francesco Romani <[email protected]>
1 parent 2d20310 commit 8d9a4cd

File tree

6 files changed

+63
-101
lines changed

6 files changed

+63
-101
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/dustin/go-humanize v1.0.1
1010
github.com/go-logr/logr v1.3.0
1111
github.com/google/go-cmp v0.6.0
12-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
12+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2
1313
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2
1414
github.com/patrickmn/go-cache v2.1.0+incompatible
1515
github.com/paypal/load-watcher v0.2.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
14971497
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
14981498
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
14991499
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
1500-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1 h1:BI3L7hNqRvXtB42FO4NI/0ZjDDVRPOMBDFLShhFtf28=
1501-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1/go.mod h1:AkACMQGiTgCt0lQw3m7TTU8PLH9lYKNK5e9DqFf5VuM=
1500+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2 h1:uAwqOtyrFYggq3pVf3hs1XKkBxrQ8dkgjWz3LCLJsiY=
1501+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2/go.mod h1:LBzS4n6GX1C69tzSd5EibZ9cGOXFuHP7GxEMDYVe1sM=
15021502
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2 h1:iFHPfZInM9pz2neye5RdmORMp1hPmte1EGJYpOOzZVg=
15031503
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2/go.mod h1:C23pM15t06dXg/OihGlqBvnYzLr+MXDXJ7zMfbNAyXI=
15041504
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=

pkg/noderesourcetopology/pluginhelpers.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ limitations under the License.
1717
package noderesourcetopology
1818

1919
import (
20-
"fmt"
21-
"strconv"
22-
"strings"
2320
"time"
2421

2522
corev1 "k8s.io/api/core/v1"
@@ -29,6 +26,7 @@ import (
2926
"k8s.io/kubernetes/pkg/scheduler/framework"
3027

3128
topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
29+
"github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/numanode"
3230

3331
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3432

@@ -108,8 +106,8 @@ func createNUMANodeList(zones topologyv1alpha2.ZoneList) NUMANodeList {
108106
continue
109107
}
110108

111-
numaID, err := getID(zone.Name)
112-
if err != nil {
109+
numaID, err := numanode.NameToID(zone.Name)
110+
if err != nil || numaID > maxNUMAId {
113111
klog.Error(err)
114112
continue
115113
}
@@ -129,28 +127,6 @@ func createNUMANodeList(zones topologyv1alpha2.ZoneList) NUMANodeList {
129127
return nodes
130128
}
131129

132-
func getID(name string) (int, error) {
133-
splitted := strings.Split(name, "-")
134-
if len(splitted) != 2 {
135-
return -1, fmt.Errorf("invalid zone format zone: %s", name)
136-
}
137-
138-
if splitted[0] != "node" {
139-
return -1, fmt.Errorf("invalid zone format zone: %s", name)
140-
}
141-
142-
numaID, err := strconv.Atoi(splitted[1])
143-
if err != nil {
144-
return -1, fmt.Errorf("invalid zone format zone: %s : %v", name, err)
145-
}
146-
147-
if numaID > maxNUMAId-1 || numaID < 0 {
148-
return -1, fmt.Errorf("invalid NUMA id range numaID: %d", numaID)
149-
}
150-
151-
return numaID, nil
152-
}
153-
154130
func extractCosts(costs topologyv1alpha2.CostList) map[int]int {
155131
nodeCosts := make(map[int]int)
156132

@@ -160,8 +136,8 @@ func extractCosts(costs topologyv1alpha2.CostList) map[int]int {
160136
}
161137

162138
for _, cost := range costs {
163-
numaID, err := getID(cost.Name)
164-
if err != nil {
139+
numaID, err := numanode.NameToID(cost.Name)
140+
if err != nil || numaID > maxNUMAId {
165141
continue
166142
}
167143
nodeCosts[numaID] = int(cost.Value)

pkg/noderesourcetopology/pluginhelpers_test.go

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,13 @@ limitations under the License.
1717
package noderesourcetopology
1818

1919
import (
20-
"fmt"
21-
"strings"
2220
"testing"
2321

2422
corev1 "k8s.io/api/core/v1"
2523
"k8s.io/apimachinery/pkg/api/resource"
2624
apiconfig "sigs.k8s.io/scheduler-plugins/apis/config"
2725
)
2826

29-
func TestGetID(t *testing.T) {
30-
testCases := []struct {
31-
description string
32-
name string
33-
expectedID int
34-
expectedErr error
35-
}{
36-
{
37-
description: "id equals 1",
38-
name: "node-1",
39-
expectedID: 1,
40-
},
41-
{
42-
description: "id equals 10",
43-
name: "node-10",
44-
expectedID: 10,
45-
},
46-
{
47-
description: "invalid format of name, node name without hyphen",
48-
name: "node0",
49-
expectedErr: fmt.Errorf("invalid zone format"),
50-
},
51-
{
52-
description: "invalid format of name, zone instead of node",
53-
name: "zone-10",
54-
expectedErr: fmt.Errorf("invalid zone format"),
55-
},
56-
{
57-
description: "invalid format of name, suffix is not an integer",
58-
name: "node-a10a",
59-
expectedErr: fmt.Errorf("invalid zone format"),
60-
},
61-
{
62-
description: "invalid format of name, suffix is not an integer",
63-
name: "node-10a",
64-
expectedErr: fmt.Errorf("invalid zone format"),
65-
},
66-
{
67-
description: "invalid numaID range",
68-
name: "node-10123412415115114",
69-
expectedErr: fmt.Errorf("invalid NUMA id range"),
70-
},
71-
}
72-
73-
for _, testCase := range testCases {
74-
t.Run(testCase.description, func(t *testing.T) {
75-
id, err := getID(testCase.name)
76-
if testCase.expectedErr == nil {
77-
if err != nil {
78-
t.Fatalf("expected err to be nil not %v", err)
79-
}
80-
81-
if id != testCase.expectedID {
82-
t.Fatalf("expected id to equal %d not %d", testCase.expectedID, id)
83-
}
84-
} else {
85-
fmt.Println(id)
86-
if !strings.Contains(err.Error(), testCase.expectedErr.Error()) {
87-
t.Fatalf("expected err: %v to contain %s", err, testCase.expectedErr)
88-
}
89-
}
90-
})
91-
}
92-
}
93-
9427
func TestOnlyNonNUMAResources(t *testing.T) {
9528
numaNodes := NUMANodeList{
9629
{

vendor/github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/numanode/numanode.go

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ github.com/jpillora/backoff
179179
# github.com/json-iterator/go v1.1.12
180180
## explicit; go 1.12
181181
github.com/json-iterator/go
182-
# github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
183-
## explicit; go 1.16
182+
# github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2
183+
## explicit; go 1.20
184184
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology
185185
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2
186186
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/attribute
187+
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/numanode
187188
# github.com/k8stopologyawareschedwg/podfingerprint v0.2.2
188189
## explicit; go 1.17
189190
github.com/k8stopologyawareschedwg/podfingerprint

0 commit comments

Comments
 (0)