diff --git a/examples/nodenumber/main.go b/examples/nodenumber/main.go index 121d639..e261632 100644 --- a/examples/nodenumber/main.go +++ b/examples/nodenumber/main.go @@ -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. @@ -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 } diff --git a/examples/nodenumber/main_test.go b/examples/nodenumber/main_test.go index 2004c05..afde1a8 100644 --- a/examples/nodenumber/main_test.go +++ b/examples/nodenumber/main_test.go @@ -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} { @@ -127,7 +127,7 @@ 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 { @@ -135,7 +135,7 @@ func (t testPod) GetUid() string { } func (t testPod) GetName() string { - return "" + return t.name } func (t testPod) GetNamespace() string { @@ -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 { diff --git a/internal/e2e/scheduler_perf/wasm/nodenumber/main.go b/internal/e2e/scheduler_perf/wasm/nodenumber/main.go index 2fb44a1..6afa175 100644 --- a/internal/e2e/scheduler_perf/wasm/nodenumber/main.go +++ b/internal/e2e/scheduler_perf/wasm/nodenumber/main.go @@ -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. } @@ -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 }