Skip to content

Commit

Permalink
fix nodenumber plugin to use Pod name instead of pod.spec.nodeName
Browse files Browse the repository at this point in the history
Signed-off-by: YZ775 <[email protected]>
  • Loading branch information
YZ775 committed Nov 15, 2024
1 parent 05231fc commit 91fdb4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/nodenumber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (pl *NodeNumber) PreScore(state api.CycleState, pod proto.Pod, _ api.NodeIn

klog.InfoS("execute PreScore on NodeNumber plugin", "pod", klog.KObj(pod))

podnum, ok := lastNumber(pod.Spec().GetNodeName())
podnum, ok := lastNumber(pod.GetName())
if !ok {
recorder.Eventf(pod, nil, "PreScore", "not match lastNumber", "Skip", "")
return nil // return success even if its suffix is non-number.
Expand All @@ -116,7 +116,7 @@ func (pl *NodeNumber) Score(state api.CycleState, pod proto.Pod, nodeName string
nodenum, ok := lastNumber(nodeName)
match = ok && data.(*preScoreState).podSuffixNumber == nodenum
} else {
// Match is also when there is no pod spec node name.
// Match is also when there is no pod name suffix.
match = true
}

Expand Down
17 changes: 8 additions & 9 deletions examples/nodenumber/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func Test_NodeNumber(t *testing.T) {
{name: "empty,empty", pod: &testPod{}, nodeName: "", expectedMatch: true},
{name: "empty,letter", pod: &testPod{}, nodeName: "a", expectedMatch: true},
{name: "empty,digit", pod: &testPod{}, nodeName: "1", expectedMatch: true},
{name: "letter,letter", pod: &testPod{nodeName: "a"}, nodeName: "a", expectedMatch: true},
{name: "letter,digit", pod: &testPod{nodeName: "a"}, nodeName: "1", expectedMatch: true},
{name: "digit,letter", pod: &testPod{nodeName: "1"}, nodeName: "a", expectedMatch: false},
{name: "digit,digit", pod: &testPod{nodeName: "1"}, nodeName: "1", expectedMatch: true},
{name: "digit,different digit", pod: &testPod{nodeName: "1"}, nodeName: "2", expectedMatch: false},
{name: "letter,letter", pod: &testPod{name: "a"}, nodeName: "a", expectedMatch: true},
{name: "letter,digit", pod: &testPod{name: "a"}, nodeName: "1", expectedMatch: true},
{name: "digit,letter", pod: &testPod{name: "1"}, nodeName: "a", expectedMatch: false},
{name: "digit,digit", pod: &testPod{name: "1"}, nodeName: "1", expectedMatch: true},
{name: "digit,different digit", pod: &testPod{name: "1"}, nodeName: "2", expectedMatch: false},
}

for _, reverse := range []bool{false, true} {
Expand Down Expand Up @@ -127,15 +127,15 @@ var _ proto.Pod = &testPod{}

// testPod is test data just to set the nodeName
type testPod struct {
nodeName string
name string
}

func (t testPod) GetUid() string {
return ""
}

func (t testPod) GetName() string {
return ""
return t.name
}

func (t testPod) GetNamespace() string {
Expand Down Expand Up @@ -163,8 +163,7 @@ func (t testPod) GetAnnotations() map[string]string {
}

func (t testPod) Spec() *protoapi.PodSpec {
nodeName := t.nodeName
return &protoapi.PodSpec{NodeName: &nodeName}
return &protoapi.PodSpec{}
}

func (t testPod) Status() *protoapi.PodStatus {
Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/scheduler_perf/wasm/nodenumber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (pl *NodeNumber) EventsToRegister() []api.ClusterEvent {

// PreScore implements api.PreScorePlugin
func (pl *NodeNumber) PreScore(state api.CycleState, pod proto.Pod, _ api.NodeInfoList) *api.Status {
podnum, ok := lastNumber(pod.Spec().GetNodeName())
podnum, ok := lastNumber(pod.GetName())
if !ok {
return nil // return success even if its suffix is non-number.
}
Expand All @@ -113,7 +113,7 @@ func (pl *NodeNumber) Score(state api.CycleState, pod proto.Pod, nodeName string
nodenum, ok := lastNumber(nodeName)
match = ok && data.(*preScoreState).podSuffixNumber == nodenum
} else {
// Match is also when there is no pod spec node name.
// Match is also when there is no pod name suffix.
match = true
}

Expand Down

0 comments on commit 91fdb4e

Please sign in to comment.