diff --git a/examples/nodenumber/main.wasm b/examples/nodenumber/main.wasm index 6d3e6853..83fcb31e 100755 Binary files a/examples/nodenumber/main.wasm and b/examples/nodenumber/main.wasm differ diff --git a/examples/nodenumber/plugin/plugin.go b/examples/nodenumber/plugin/plugin.go index 22e818b7..29ccc5e4 100644 --- a/examples/nodenumber/plugin/plugin.go +++ b/examples/nodenumber/plugin/plugin.go @@ -91,7 +91,7 @@ func (pl *NodeNumber) EventsToRegister() []api.ClusterEvent { // PreScore implements api.PreScorePlugin func (pl *NodeNumber) PreScore(state api.CycleState, pod proto.Pod, _ proto.NodeList) *api.Status { - podnum, ok := lastNumber(pod.Spec().NodeName) + podnum, ok := lastNumber(pod.Spec().GetNodeName()) if !ok { return nil // return success even if its suffix is non-number. } @@ -105,7 +105,7 @@ func (pl *NodeNumber) Score(state api.CycleState, _ proto.Pod, nodeName string) var match bool if data, ok := state.Read(preScoreStateKey); ok { // Match is when there is a last digit, and it is the pod suffix. - nodenum, ok := lastNumber(&nodeName) + nodenum, ok := lastNumber(nodeName) match = ok && data.(*preScoreState).podSuffixNumber == nodenum } else { // Match is also when there is no pod spec node name. @@ -122,13 +122,8 @@ func (pl *NodeNumber) Score(state api.CycleState, _ proto.Pod, nodeName string) return 0, nil } -// lastNumber returns the last number in the string being pointed to or false. -func lastNumber(ptr *string) (uint8, bool) { - // Early exit on nil or empty string. - if ptr == nil { - return 0, false - } - str := *ptr +// lastNumber returns the last number in the string or false. +func lastNumber(str string) (uint8, bool) { if len(str) == 0 { return 0, false } diff --git a/examples/nodenumber/plugin/plugin_test.go b/examples/nodenumber/plugin/plugin_test.go index 84a9f769..515f34c6 100644 --- a/examples/nodenumber/plugin/plugin_test.go +++ b/examples/nodenumber/plugin/plugin_test.go @@ -22,7 +22,6 @@ import ( "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto" protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" - meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" ) func Test_NodeNumber(t *testing.T) { @@ -36,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: stringPtr("a")}, nodeName: "a", expectedMatch: true}, - {name: "letter,digit", pod: &testPod{nodeName: stringPtr("a")}, nodeName: "1", expectedMatch: true}, - {name: "digit,letter", pod: &testPod{nodeName: stringPtr("1")}, nodeName: "a", expectedMatch: false}, - {name: "digit,digit", pod: &testPod{nodeName: stringPtr("1")}, nodeName: "1", expectedMatch: true}, - {name: "digit,different digit", pod: &testPod{nodeName: stringPtr("1")}, nodeName: "2", expectedMatch: false}, + {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}, } for _, reverse := range []bool{false, true} { @@ -82,18 +81,17 @@ func Test_NodeNumber(t *testing.T) { func Test_lastNumber(t *testing.T) { tests := []struct { name string - input *string + input string expectedDigit uint8 expectedOk bool }{ - {name: "nil"}, - {name: "empty", input: stringPtr("")}, - {name: "not digit", input: stringPtr("a")}, - {name: "unicode", input: stringPtr("ó")}, - {name: "middle digit", input: stringPtr("a1a")}, - {name: "digit after letter", input: stringPtr("a1"), expectedDigit: 1, expectedOk: true}, - {name: "digit after digit", input: stringPtr("12"), expectedDigit: 2, expectedOk: true}, - {name: "digit after unicode", input: stringPtr("ó2"), expectedDigit: 2, expectedOk: true}, + {name: "empty", input: ""}, + {name: "not digit", input: "a"}, + {name: "unicode", input: "ó"}, + {name: "middle digit", input: "a1a"}, + {name: "digit after letter", input: "a1", expectedDigit: 1, expectedOk: true}, + {name: "digit after digit", input: "12", expectedDigit: 2, expectedOk: true}, + {name: "digit after unicode", input: "ó2", expectedDigit: 2, expectedOk: true}, } for _, tc := range tests { @@ -109,10 +107,6 @@ func Test_lastNumber(t *testing.T) { } } -func stringPtr(s string) *string { - return &s -} - var _ api.CycleState = testCycleState{} type testCycleState map[string]any @@ -134,15 +128,24 @@ var _ proto.Pod = &testPod{} // testPod is test data just to set the nodeName type testPod struct { - nodeName *string + nodeName string } -func (t testPod) Metadata() *meta.ObjectMeta { - return nil +func (t testPod) GetUid() string { + return "" +} + +func (t testPod) GetName() string { + return "" +} + +func (t testPod) GetNamespace() string { + return "" } func (t testPod) Spec() *protoapi.PodSpec { - return &protoapi.PodSpec{NodeName: t.nodeName} + nodeName := t.nodeName + return &protoapi.PodSpec{NodeName: &nodeName} } func (t testPod) Status() *protoapi.PodStatus { diff --git a/guest/api/proto/proto.go b/guest/api/proto/proto.go index 5ee2d8e2..afe30d07 100644 --- a/guest/api/proto/proto.go +++ b/guest/api/proto/proto.go @@ -19,22 +19,29 @@ package proto import ( api "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" - meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" ) +// Metadata are fields on top-level types, used for logging and metrics. +type Metadata interface { + GetUid() string + GetName() string + GetNamespace() string +} + type Node interface { - Metadata() *meta.ObjectMeta + Metadata + Spec() *api.NodeSpec Status() *api.NodeStatus } type NodeList interface { - Metadata() *meta.ListMeta - Items() []*api.Node + Items() []Node } type Pod interface { - Metadata() *meta.ObjectMeta + Metadata + Spec() *api.PodSpec Status() *api.PodStatus } diff --git a/guest/filter/filter.go b/guest/filter/filter.go index e0de1665..6f1d6211 100644 --- a/guest/filter/filter.go +++ b/guest/filter/filter.go @@ -24,8 +24,8 @@ import ( "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/cyclestate" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/imports" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/plugin" + internalproto "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/proto" protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" - meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" ) // filter is the current plugin assigned with SetPlugin. @@ -79,27 +79,15 @@ var _ api.NodeInfo = (*nodeInfo)(nil) // // Note: Unlike proto.Pod, this is not special cased for the scheduling cycle. type nodeInfo struct { - node *protoapi.Node + node proto.Node } func (n *nodeInfo) Node() proto.Node { - return n -} - -func (n *nodeInfo) Metadata() *meta.ObjectMeta { - return n.lazyNode().Metadata -} - -func (n *nodeInfo) Spec() *protoapi.NodeSpec { - return n.lazyNode().Spec -} - -func (n *nodeInfo) Status() *protoapi.NodeStatus { - return n.lazyNode().Status + return n.lazyNode() } // lazyNode lazy initializes node from imports.Node. -func (n *nodeInfo) lazyNode() *protoapi.Node { +func (n *nodeInfo) lazyNode() proto.Node { if node := n.node; node != nil { return node } @@ -108,6 +96,6 @@ func (n *nodeInfo) lazyNode() *protoapi.Node { if err := imports.Node(msg.UnmarshalVT); err != nil { panic(err.Error()) } - n.node = &msg + n.node = &internalproto.Node{Msg: &msg} return n.node } diff --git a/guest/internal/prefilter/types.go b/guest/internal/prefilter/types.go index 03663001..772ebf79 100644 --- a/guest/internal/prefilter/types.go +++ b/guest/internal/prefilter/types.go @@ -4,8 +4,8 @@ import ( "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/imports" + internalproto "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/proto" protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" - meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" ) // Pod is exposed for the cyclestate package. @@ -33,8 +33,16 @@ func (cycleState) Delete(key string) { type pod struct{} -func (pod) Metadata() *meta.ObjectMeta { - return lazyPod().Metadata +func (pod) GetName() string { + return internalproto.GetName(lazyPod()) +} + +func (pod) GetNamespace() string { + return internalproto.GetNamespace(lazyPod()) +} + +func (pod) GetUid() string { + return internalproto.GetUid(lazyPod()) } func (pod) Spec() *protoapi.PodSpec { diff --git a/guest/internal/proto/proto.go b/guest/internal/proto/proto.go new file mode 100644 index 00000000..cbaccfe7 --- /dev/null +++ b/guest/internal/proto/proto.go @@ -0,0 +1,74 @@ +/* + Copyright 2023 The Kubernetes Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package proto + +import ( + "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto" + protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" + meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" +) + +type object interface { + GetMetadata() *meta.ObjectMeta +} + +func GetName[O object](o O) string { + if md := o.GetMetadata(); md != nil && md.Name != nil { + return *md.Name + } + return "" +} + +func GetNamespace[O object](o O) string { + if md := o.GetMetadata(); md != nil && md.Namespace != nil { + return *md.Namespace + } + return "" +} + +func GetUid[O object](o O) string { + if md := o.GetMetadata(); md != nil && md.Uid != nil { + return *md.Uid + } + return "" +} + +var _ proto.Node = (*Node)(nil) + +type Node struct { + Msg *protoapi.Node +} + +func (o *Node) GetName() string { + return GetName(o.Msg) +} + +func (o *Node) GetNamespace() string { + return GetNamespace(o.Msg) +} + +func (o *Node) GetUid() string { + return GetUid(o.Msg) +} + +func (o *Node) Spec() *protoapi.NodeSpec { + return o.Msg.Spec +} + +func (o *Node) Status() *protoapi.NodeStatus { + return o.Msg.Status +} diff --git a/guest/prescore/imports.go b/guest/prescore/imports.go new file mode 100644 index 00000000..ece582f5 --- /dev/null +++ b/guest/prescore/imports.go @@ -0,0 +1,24 @@ +//go:build tinygo.wasm + +/* + Copyright 2023 The Kubernetes Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package prescore + +import "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/mem" + +//go:wasmimport k8s.io/api nodeList +func k8sApiNodeList(ptr uint32, limit mem.BufLimit) (len uint32) diff --git a/guest/prescore/imports_stub.go b/guest/prescore/imports_stub.go new file mode 100644 index 00000000..4c8a4a3f --- /dev/null +++ b/guest/prescore/imports_stub.go @@ -0,0 +1,24 @@ +//go:build !tinygo.wasm + +/* + Copyright 2023 The Kubernetes Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package prescore + +import "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/mem" + +// k8sApiNodeList is stubbed for compilation outside TinyGo. +func k8sApiNodeList(uint32, mem.BufLimit) (len uint32) { return } diff --git a/guest/prescore/prescore.go b/guest/prescore/prescore.go index 96583360..5ffa4bd1 100644 --- a/guest/prescore/prescore.go +++ b/guest/prescore/prescore.go @@ -20,11 +20,13 @@ package prescore import ( "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api" + "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/cyclestate" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/imports" + "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/mem" "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/plugin" + internalproto "sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/proto" protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api" - meta "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta" ) // prescore is the current plugin assigned with SetPlugin. @@ -89,27 +91,36 @@ func _prescore() uint32 { // // Note: Unlike proto.Pod, this is not special cased for the scheduling cycle. type nodeList struct { - nl *protoapi.NodeList + items []proto.Node } -func (n *nodeList) Metadata() *meta.ListMeta { - return n.lazyNodeList().Metadata +func (n *nodeList) Items() []proto.Node { + return n.lazyItems() } -func (n *nodeList) Items() []*protoapi.Node { - return n.lazyNodeList().Items -} - -// lazyNodeList lazy initializes node from imports.NodeList. -func (n *nodeList) lazyNodeList() *protoapi.NodeList { - if nl := n.nl; nl != nil { - return nl +// lazyItems lazy initializes the nodes from lodeList. +func (n *nodeList) lazyItems() []proto.Node { + if items := n.items; items != nil { + return items } var msg protoapi.NodeList - if err := imports.Node(msg.UnmarshalVT); err != nil { + // Wrap to avoid TinyGo 0.28: cannot use an exported function as value + if err := mem.Update(func(ptr uint32, limit mem.BufLimit) (len uint32) { + return k8sApiNodeList(ptr, limit) + }, msg.UnmarshalVT); err != nil { panic(err.Error()) } - n.nl = &msg - return n.nl + + size := len(msg.Items) + if size == 0 { + return nil + } + + items := make([]proto.Node, size) + for i := range msg.Items { + items[i] = &internalproto.Node{Msg: msg.Items[i]} + } + n.items = items + return items } diff --git a/guest/testdata/all/main.wasm b/guest/testdata/all/main.wasm index 3299642a..33689456 100755 Binary files a/guest/testdata/all/main.wasm and b/guest/testdata/all/main.wasm differ diff --git a/guest/testdata/cyclestate/main.wasm b/guest/testdata/cyclestate/main.wasm index 00941a2c..bdac6326 100755 Binary files a/guest/testdata/cyclestate/main.wasm and b/guest/testdata/cyclestate/main.wasm differ diff --git a/guest/testdata/filter/main.go b/guest/testdata/filter/main.go index 0dbac72d..f9d1e6e3 100644 --- a/guest/testdata/filter/main.go +++ b/guest/testdata/filter/main.go @@ -71,7 +71,7 @@ type preFilterPlugin struct{ noopPlugin } func (preFilterPlugin) PreFilter(_ api.CycleState, pod proto.Pod) ([]string, *api.Status) { // First, check if the pod spec node name is empty. If so, pass! - podSpecNodeName := nilToEmpty(pod.Spec().NodeName) + podSpecNodeName := pod.Spec().GetNodeName() if len(podSpecNodeName) == 0 { return nil, nil } @@ -83,13 +83,13 @@ type filterPlugin struct{ noopPlugin } func (filterPlugin) Filter(_ api.CycleState, pod proto.Pod, nodeInfo api.NodeInfo) *api.Status { // First, check if the pod spec node name is empty. If so, pass! - podSpecNodeName := nilToEmpty(pod.Spec().NodeName) + podSpecNodeName := pod.Spec().GetNodeName() if len(podSpecNodeName) == 0 { return nil } // Next, check if the node name matches the spec node. If so, pass! - nodeName := nilToEmpty(nodeInfo.Node().Metadata().Name) + nodeName := nodeInfo.Node().GetName() if podSpecNodeName == nodeName { return nil } @@ -100,10 +100,3 @@ func (filterPlugin) Filter(_ api.CycleState, pod proto.Pod, nodeInfo api.NodeInf Reason: podSpecNodeName + " != " + nodeName, } } - -func nilToEmpty(ptr *string) string { - if ptr != nil { - return *ptr - } - return "" -} diff --git a/guest/testdata/filter/main.wasm b/guest/testdata/filter/main.wasm index e4218079..f8aee622 100755 Binary files a/guest/testdata/filter/main.wasm and b/guest/testdata/filter/main.wasm differ diff --git a/guest/testdata/score/main.go b/guest/testdata/score/main.go index c5550d58..752aa189 100644 --- a/guest/testdata/score/main.go +++ b/guest/testdata/score/main.go @@ -78,16 +78,9 @@ func (preScorePlugin) PreScore(_ api.CycleState, _ proto.Pod, nodeList proto.Nod type scorePlugin struct{ noopPlugin } func (scorePlugin) Score(_ api.CycleState, pod proto.Pod, nodeName string) (int32, *api.Status) { - podSpecNodeName := nilToEmpty(pod.Spec().NodeName) + podSpecNodeName := pod.Spec().GetNodeName() if nodeName == podSpecNodeName { return 100, nil } return 0, nil } - -func nilToEmpty(ptr *string) string { - if ptr != nil { - return *ptr - } - return "" -} diff --git a/guest/testdata/score/main.wasm b/guest/testdata/score/main.wasm index 694e967c..35bd304f 100755 Binary files a/guest/testdata/score/main.wasm and b/guest/testdata/score/main.wasm differ diff --git a/internal/e2e/go.mod b/internal/e2e/go.mod index ba5f3886..e9ea32db 100644 --- a/internal/e2e/go.mod +++ b/internal/e2e/go.mod @@ -6,7 +6,7 @@ go 1.20 require ( github.com/labstack/echo v3.3.10+incompatible github.com/stealthrocket/wzprof v0.1.5 - github.com/tetratelabs/wazero v1.3.0 + github.com/tetratelabs/wazero v1.3.1 go.uber.org/zap v1.19.0 k8s.io/api v0.27.3 k8s.io/apimachinery v0.27.3 diff --git a/internal/e2e/go.sum b/internal/e2e/go.sum index c20df12e..335f5b0a 100644 --- a/internal/e2e/go.sum +++ b/internal/e2e/go.sum @@ -407,8 +407,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/tetratelabs/wazero v1.3.0 h1:nqw7zCldxE06B8zSZAY0ACrR9OH5QCcPwYmYlwtcwtE= -github.com/tetratelabs/wazero v1.3.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= +github.com/tetratelabs/wazero v1.3.1 h1:rnb9FgOEQRLLR8tgoD1mfjNjMhFeWRUk+a4b4j/GpUM= +github.com/tetratelabs/wazero v1.3.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= diff --git a/internal/e2e/scheduler_perf/scheduler_perf_test.go b/internal/e2e/scheduler_perf/scheduler_perf_test.go index 66dd9a8f..2f44b8d6 100644 --- a/internal/e2e/scheduler_perf/scheduler_perf_test.go +++ b/internal/e2e/scheduler_perf/scheduler_perf_test.go @@ -22,7 +22,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "math" "os" "path" @@ -607,7 +606,7 @@ func initTestOutput(tb testing.TB) io.Writer { if err := fileOutput.Close(); err != nil { tb.Fatalf("close log file: %v", err) } - log, err := ioutil.ReadFile(logfileName) + log, err := os.ReadFile(logfileName) if err != nil { tb.Fatalf("read log file: %v", err) } @@ -812,7 +811,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [ b.Fatalf("op %d: %v", opIndex, err) } if err := nsPreparer.prepare(ctx); err != nil { - nsPreparer.cleanup(ctx) + _ = nsPreparer.cleanup(ctx) b.Fatalf("op %d: %v", opIndex, err) } for _, n := range nsPreparer.namespaces() { @@ -859,11 +858,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [ if concreteOp.SkipWaitToCompletion { // Only record those namespaces that may potentially require barriers // in the future. - if _, ok := numPodsScheduledPerNamespace[namespace]; ok { - numPodsScheduledPerNamespace[namespace] += concreteOp.Count - } else { - numPodsScheduledPerNamespace[namespace] = concreteOp.Count - } + numPodsScheduledPerNamespace[namespace] += concreteOp.Count } else { if err := waitUntilPodsScheduledInNamespace(ctx, b, podInformer, namespace, concreteOp.Count); err != nil { b.Fatalf("op %d: error in waiting for pods to get scheduled: %v", opIndex, err) @@ -925,7 +920,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [ churnFns = append(churnFns, func(name string) string { if name != "" { - dynRes.Delete(ctx, name, metav1.DeleteOptions{}) + _ = dynRes.Delete(ctx, name, metav1.DeleteOptions{}) return "" } @@ -1085,7 +1080,7 @@ func createPods(ctx context.Context, b *testing.B, namespace string, cpo *create // namespace are scheduled. Times out after 10 minutes because even at the // lowest observed QPS of ~10 pods/sec, a 5000-node test should complete. func waitUntilPodsScheduledInNamespace(ctx context.Context, b *testing.B, podInformer coreinformers.PodInformer, namespace string, wantCount int) error { - return wait.PollImmediate(1*time.Second, 10*time.Minute, func() (bool, error) { + return wait.PollImmediate(1*time.Second, 10*time.Minute, func() (bool, error) { //nolint:staticcheck // TODO: deprecated select { case <-ctx.Done(): return true, ctx.Err() @@ -1200,8 +1195,6 @@ func validateTestCases(testCases []*testCase) error { return nil } -var count = 1 - func getPodStrategy(cpo *createPodsOp) (testutils.TestPodCreateStrategy, error) { basePod := makeBasePod() if cpo.PodTemplatePath != nil { diff --git a/scheduler/go.mod b/scheduler/go.mod index 5a4edbf0..25bd8f44 100644 --- a/scheduler/go.mod +++ b/scheduler/go.mod @@ -36,7 +36,7 @@ replace ( require ( github.com/google/uuid v1.3.0 - github.com/tetratelabs/wazero v1.3.0 + github.com/tetratelabs/wazero v1.3.1 k8s.io/api v0.27.3 k8s.io/apimachinery v0.27.3 k8s.io/component-base v0.27.3 diff --git a/scheduler/go.sum b/scheduler/go.sum index b8061722..29f7c63d 100644 --- a/scheduler/go.sum +++ b/scheduler/go.sum @@ -320,8 +320,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/tetratelabs/wazero v1.3.0 h1:nqw7zCldxE06B8zSZAY0ACrR9OH5QCcPwYmYlwtcwtE= -github.com/tetratelabs/wazero v1.3.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= +github.com/tetratelabs/wazero v1.3.1 h1:rnb9FgOEQRLLR8tgoD1mfjNjMhFeWRUk+a4b4j/GpUM= +github.com/tetratelabs/wazero v1.3.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/scheduler/plugin/plugin_test.go b/scheduler/plugin/plugin_test.go index a52ebebd..c9b46634 100644 --- a/scheduler/plugin/plugin_test.go +++ b/scheduler/plugin/plugin_test.go @@ -548,21 +548,21 @@ func TestPreScore(t *testing.T) { name: "success: no nodes", pod: test.PodSmall, args: []string{"test", "preScore"}, - expectedStatusCode: framework.Success, + expectedStatusCode: 0, // count of nodes }, { name: "success: one node", args: []string{"test", "preScore"}, nodes: []*v1.Node{test.NodeSmall}, pod: &v1.Pod{ObjectMeta: test.PodSmall.ObjectMeta}, - expectedStatusCode: framework.Success, + expectedStatusCode: 1, // count of nodes }, { name: "success: two nodes", args: []string{"test", "preScore"}, nodes: []*v1.Node{test.NodeSmall, test.NodeReal}, pod: &v1.Pod{ObjectMeta: test.PodSmall.ObjectMeta}, - expectedStatusCode: framework.Success, + expectedStatusCode: 2, // count of nodes }, { name: "min statusCode",