Skip to content

Commit

Permalink
add nodeToStatus proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekko0114 committed Nov 4, 2023
1 parent 02eb28d commit 3efa4ed
Show file tree
Hide file tree
Showing 13 changed files with 792 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ submodule-update:
.PHONY: update-kubernetes-proto
update-kubernetes-proto: proto-tools
echo "Regenerate the Go protobuf code."
protoc ./kubernetes/proto/nodetostatus/api.proto --go-plugin_out=./kubernetes/proto/nodetostatus \
--go-plugin_opt=Mkubernetes/proto/nodetostatus/api.proto=.; \
cd kubernetes/kubernetes/staging/src/; \
protoc ./k8s.io/apimachinery/pkg/api/resource/generated.proto --go-plugin_out=../../../proto \
--go-plugin_opt=Mk8s.io/apimachinery/pkg/api/resource/generated.proto=./resource; \
Expand Down
42 changes: 37 additions & 5 deletions guest/postfilter/postfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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"

"sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/nodetostatus"
)

// postfilter is the current plugin assigned with SetPlugin.
Expand Down Expand Up @@ -75,10 +76,9 @@ func _postfilter() uint64 { //nolint
return 0
}

// TODO: fix PostFilter
// The parameters passed are lazy with regard to host functions. This means
// a no-op plugin should not have any unmarshal penalty.
nominatedNodeName, nominatingMode, status := postfilter.PostFilter(cyclestate.Values, cyclestate.Pod, nil)
nominatedNodeName, nominatingMode, status := postfilter.PostFilter(cyclestate.Values, cyclestate.Pod, &nodeToStatusMap{})

cString := []byte(nominatedNodeName)
if cString != nil {
Expand All @@ -101,10 +101,42 @@ func (n *nodeToStatusMap) NodeToStatusMap() map[string]*api.Status {

// lazyNodeToStatusMap returns NodeToStatusMap from imports.NodeToStatusMap.
func (n *nodeToStatusMap) lazyNodeToStatusMap() map[string]*api.Status {
var msg api.NodeToStatusMap
var msg nodetostatus.NodeToStatusMap
if err := imports.NodeToStatusMap(msg.UnmarshalVT); err != nil {
panic(err.Error())
}
n.statusMap = &internalproto.NodeToStatusMap{Msg: &msg}
n.statusMap = convertNodeStatusMapType(msg.NodeStatus)
return n.statusMap
}

func convertNodeStatusMapType(nodeToStatusMap map[string]*nodetostatus.Status) map[string]*api.Status {
converted := make(map[string]*api.Status)

for key, value := range nodeToStatusMap {
convertedStatus := &api.Status{
Code: convertCode(*value.Code),
Reason: *value.Reason,
}
converted[key] = convertedStatus
}
return converted
}

func convertCode(code nodetostatus.StatusCode) api.StatusCode {
switch code {
case nodetostatus.StatusCode_STATUS_CODE_SUCCESS:
return api.StatusCodeSuccess
case nodetostatus.StatusCode_STATUS_CODE_ERROR:
return api.StatusCodeError
case nodetostatus.StatusCode_STATUS_CODE_UNSCHEDULABLE:
return api.StatusCodeUnschedulable
case nodetostatus.StatusCode_STATUS_CODE_UNSCHEDULABLE_AND_UNRESOLVABLE:
return api.StatusCodeUnschedulableAndUnresolvable
case nodetostatus.StatusCode_STATUS_CODE_WAIT:
return api.StatusCodeWait
case nodetostatus.StatusCode_STATUS_CODE_SKIP:
return api.StatusCodeSkip
default:
panic("StatusCode can't be converted")
}
}
5 changes: 5 additions & 0 deletions internal/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func RunAll(ctx context.Context, t Testing, plugin framework.Plugin, pod *v1.Pod
RequireSuccess(t, s)
}

if postfilterP, ok := plugin.(framework.PostFilterPlugin); ok {
_, s = postfilterP.PostFilter(ctx, nil, pod, nil)
RequireSuccess(t, s)
}

if prescoreP, ok := plugin.(framework.PreScorePlugin); ok {
s = prescoreP.PreScore(ctx, nil, pod, []*v1.Node{ni.Node()})
RequireSuccess(t, s)
Expand Down
3 changes: 2 additions & 1 deletion internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/gcfg.v1 v1.2.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
Expand All @@ -191,6 +191,7 @@ require (
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto v0.0.0-20230808005812-6708ed44fd99 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/scheduler_perf/scheduler_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var (
Metrics: map[string]*labelValues{
"scheduler_framework_extension_point_duration_seconds": {
label: extensionPointsLabelName,
values: []string{"PreFilter", "Filter", "PreScore", "Score"},
values: []string{"PreFilter", "Filter", "PostFilter", "PreScore", "Score"},
},
"scheduler_scheduling_attempt_duration_seconds": nil,
"scheduler_pod_scheduling_duration_seconds": nil,
Expand Down
102 changes: 102 additions & 0 deletions kubernetes/proto/nodetostatus/api.pb.go

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

21 changes: 21 additions & 0 deletions kubernetes/proto/nodetostatus/api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto2";

option go_package = "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/nodetostatus";

enum StatusCode {
STATUS_CODE_SUCCESS = 0;
STATUS_CODE_ERROR = 1;
STATUS_CODE_UNSCHEDULABLE = 2;
STATUS_CODE_UNSCHEDULABLE_AND_UNRESOLVABLE = 3;
STATUS_CODE_WAIT = 4;
STATUS_CODE_SKIP = 5;
}

message Status {
required StatusCode code = 1;
required string reason = 2;
};

message NodeToStatusMap {
map<string, Status> nodeStatus = 1;
}
Loading

0 comments on commit 3efa4ed

Please sign in to comment.