Skip to content

Commit

Permalink
nrt: deps: bump to noderesourcetopology API v0.1.2
Browse files Browse the repository at this point in the history
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 <fromani@redhat.com>
  • Loading branch information
ffromani committed Apr 19, 2024
1 parent 2d20310 commit 8d9a4cd
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 101 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/go-logr/logr v1.3.0
github.com/google/go-cmp v0.6.0
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/paypal/load-watcher v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1 h1:BI3L7hNqRvXtB42FO4NI/0ZjDDVRPOMBDFLShhFtf28=
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1/go.mod h1:AkACMQGiTgCt0lQw3m7TTU8PLH9lYKNK5e9DqFf5VuM=
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2 h1:uAwqOtyrFYggq3pVf3hs1XKkBxrQ8dkgjWz3LCLJsiY=
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2/go.mod h1:LBzS4n6GX1C69tzSd5EibZ9cGOXFuHP7GxEMDYVe1sM=
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2 h1:iFHPfZInM9pz2neye5RdmORMp1hPmte1EGJYpOOzZVg=
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2/go.mod h1:C23pM15t06dXg/OihGlqBvnYzLr+MXDXJ7zMfbNAyXI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
Expand Down
34 changes: 5 additions & 29 deletions pkg/noderesourcetopology/pluginhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ limitations under the License.
package noderesourcetopology

import (
"fmt"
"strconv"
"strings"
"time"

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

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

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

Expand Down Expand Up @@ -108,8 +106,8 @@ func createNUMANodeList(zones topologyv1alpha2.ZoneList) NUMANodeList {
continue
}

numaID, err := getID(zone.Name)
if err != nil {
numaID, err := numanode.NameToID(zone.Name)
if err != nil || numaID > maxNUMAId {
klog.Error(err)
continue
}
Expand All @@ -129,28 +127,6 @@ func createNUMANodeList(zones topologyv1alpha2.ZoneList) NUMANodeList {
return nodes
}

func getID(name string) (int, error) {
splitted := strings.Split(name, "-")
if len(splitted) != 2 {
return -1, fmt.Errorf("invalid zone format zone: %s", name)
}

if splitted[0] != "node" {
return -1, fmt.Errorf("invalid zone format zone: %s", name)
}

numaID, err := strconv.Atoi(splitted[1])
if err != nil {
return -1, fmt.Errorf("invalid zone format zone: %s : %v", name, err)
}

if numaID > maxNUMAId-1 || numaID < 0 {
return -1, fmt.Errorf("invalid NUMA id range numaID: %d", numaID)
}

return numaID, nil
}

func extractCosts(costs topologyv1alpha2.CostList) map[int]int {
nodeCosts := make(map[int]int)

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

for _, cost := range costs {
numaID, err := getID(cost.Name)
if err != nil {
numaID, err := numanode.NameToID(cost.Name)
if err != nil || numaID > maxNUMAId {
continue
}
nodeCosts[numaID] = int(cost.Value)
Expand Down
67 changes: 0 additions & 67 deletions pkg/noderesourcetopology/pluginhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,13 @@ limitations under the License.
package noderesourcetopology

import (
"fmt"
"strings"
"testing"

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

func TestGetID(t *testing.T) {
testCases := []struct {
description string
name string
expectedID int
expectedErr error
}{
{
description: "id equals 1",
name: "node-1",
expectedID: 1,
},
{
description: "id equals 10",
name: "node-10",
expectedID: 10,
},
{
description: "invalid format of name, node name without hyphen",
name: "node0",
expectedErr: fmt.Errorf("invalid zone format"),
},
{
description: "invalid format of name, zone instead of node",
name: "zone-10",
expectedErr: fmt.Errorf("invalid zone format"),
},
{
description: "invalid format of name, suffix is not an integer",
name: "node-a10a",
expectedErr: fmt.Errorf("invalid zone format"),
},
{
description: "invalid format of name, suffix is not an integer",
name: "node-10a",
expectedErr: fmt.Errorf("invalid zone format"),
},
{
description: "invalid numaID range",
name: "node-10123412415115114",
expectedErr: fmt.Errorf("invalid NUMA id range"),
},
}

for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
id, err := getID(testCase.name)
if testCase.expectedErr == nil {
if err != nil {
t.Fatalf("expected err to be nil not %v", err)
}

if id != testCase.expectedID {
t.Fatalf("expected id to equal %d not %d", testCase.expectedID, id)
}
} else {
fmt.Println(id)
if !strings.Contains(err.Error(), testCase.expectedErr.Error()) {
t.Fatalf("expected err: %v to contain %s", err, testCase.expectedErr)
}
}
})
}
}

func TestOnlyNonNUMAResources(t *testing.T) {
numaNodes := NUMANodeList{
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ github.com/jpillora/backoff
# github.com/json-iterator/go v1.1.12
## explicit; go 1.12
github.com/json-iterator/go
# github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
## explicit; go 1.16
# github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2
## explicit; go 1.20
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/attribute
github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2/helper/numanode
# github.com/k8stopologyawareschedwg/podfingerprint v0.2.2
## explicit; go 1.17
github.com/k8stopologyawareschedwg/podfingerprint
Expand Down

0 comments on commit 8d9a4cd

Please sign in to comment.