Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ gofumpt := mvdan.cc/[email protected]
gosimports := github.com/rinchsan/gosimports/cmd/[email protected]
golangci_lint := github.com/golangci/golangci-lint/cmd/[email protected]

examples/advanced/main.wasm: examples/advanced/main.go
@(cd $(@D); tinygo build -o main.wasm -gc=custom -tags=custommalloc -scheduler=none --no-debug -target=wasi .)

internal/e2e/scheduler_perf/wasm/nodenumber/main.wasm: internal/e2e/scheduler_perf/wasm/nodenumber/main.go
@(cd $(@D); tinygo build -o main.wasm -gc=custom -tags=custommalloc -scheduler=none --no-debug -target=wasi .)

%/main.wasm: %/main.go
@(cd $(@D); tinygo build -o main.wasm -scheduler=none --no-debug -target=wasi .)
@(cd $(@D); GOARCH=wasm GOOS=wasip1 gotip build -buildmode=c-shared -tags wasm -o main.wasm .)

.PHONY: build-tinygo
build-tinygo: examples/nodenumber/main.wasm examples/advanced/main.wasm examples/imagelocality/main.wasm guest/testdata/cyclestate/main.wasm guest/testdata/filter/main.wasm guest/testdata/score/main.wasm \
.PHONY: build-wasm
build-wasm: examples/nodenumber/main.wasm examples/advanced/main.wasm examples/imagelocality/main.wasm guest/testdata/cyclestate/main.wasm guest/testdata/filter/main.wasm guest/testdata/score/main.wasm \
guest/testdata/bind/main.wasm guest/testdata/reserve/main.wasm guest/testdata/handle/main.wasm guest/testdata/permit/main.wasm \
internal/e2e/scheduler_perf/wasm/nodenumber/main.wasm

Expand Down Expand Up @@ -46,7 +40,7 @@ build-wat: $(wildcard scheduler/test/testdata/*/*.wat)
done

.PHONY: testdata
testdata: build-tinygo build-wat
testdata: build-wasm build-wat

.PHONY: profile
profile: examples/advanced/main-debug.wasm
Expand Down
6 changes: 1 addition & 5 deletions examples/advanced/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ module sigs.k8s.io/kube-scheduler-wasm-extension/examples/advanced
go 1.22.0

require (
github.com/wasilibs/nottinygc v0.4.0
sigs.k8s.io/kube-scheduler-wasm-extension/guest v0.0.0-00010101000000-000000000000
sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto v0.0.0-00010101000000-000000000000
)

require (
github.com/magefile/mage v1.14.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
require google.golang.org/protobuf v1.30.0 // indirect

replace sigs.k8s.io/kube-scheduler-wasm-extension/guest => ./../../guest

Expand Down
5 changes: 0 additions & 5 deletions examples/advanced/go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/wasilibs/nottinygc v0.4.0 h1:h1TJMihMC4neN6Zq+WKpLxgd9xCFMw7O9ETLwY2exJQ=
github.com/wasilibs/nottinygc v0.4.0/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
Expand Down
10 changes: 3 additions & 7 deletions examples/advanced/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tinygo.wasm

/*
Copyright 2023 The Kubernetes Authors.

Expand All @@ -20,11 +18,7 @@
// 'tinygo build -target=wasi'. See /guest/RATIONALE.md for details.
package main

// Override the default GC with a more performant one.
// Note: this requires tinygo flags: -gc=custom -tags=custommalloc
import (
_ "github.com/wasilibs/nottinygc"

"sigs.k8s.io/kube-scheduler-wasm-extension/examples/advanced/plugin"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/config"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/enqueue"
Expand All @@ -36,7 +30,7 @@ import (

// main is compiled to an exported Wasm function named "_start", called by the
// Wasm scheduler plugin during initialization.
func main() {
func init() {
// The plugin package uses only normal Go code, which allows it to be
// unit testable via `tinygo test -target=wasi` as well normal `go test`.
//
Expand All @@ -53,3 +47,5 @@ func main() {
prescore.SetPlugin(plugin)
score.SetPlugin(plugin)
}

func main() {}
Binary file modified examples/advanced/main.wasm
100755 → 100644
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/imagelocality/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (

// main is compiled to an exported Wasm function named "_start", called by the
// Wasm scheduler plugin during initialization.
func main() {
func main() {}
func init() {
// The plugin package uses only normal Go code, which allows it to be
// unit testable via `tinygo test -target=wasi` as well normal `go test`.
//
Expand Down
Binary file modified examples/imagelocality/main.wasm
100755 → 100644
Binary file not shown.
4 changes: 3 additions & 1 deletion examples/nodenumber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ import (

// main is compiled to a WebAssembly function named "_start", called by the
// wasm scheduler plugin during initialization.
func main() {
func init() {
p, err := New(klog.Get(), config.Get())
if err != nil {
panic(err)
}
plugin.Set(p)
}

func main() {}

func New(klog klogapi.Klog, jsonConfig []byte) (api.Plugin, error) {
var args nodeNumberArgs
if jsonConfig != nil {
Expand Down
Binary file modified examples/nodenumber/main.wasm
100755 → 100644
Binary file not shown.
2 changes: 1 addition & 1 deletion guest/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ func() uint32 = _bind

// _bind is only exported to the host.
//
//export bind
//go:wasmexport bind
func _bind() uint32 { //nolint
if bind == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/config/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/config/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/enqueue/enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ func() = _enqueue

// enqueue is only exported to the host.
//
//export enqueue
//go:wasmexport enqueue
func _enqueue() {
if enqueue == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/enqueue/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/enqueue/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ func() uint32 = _filter

// filter is only exported to the host.
//
//export filter
//go:wasmexport filter
func _filter() uint32 { //nolint
if filter == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/handle/eventrecorder/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/handle/eventrecorder/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/handle/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/handle/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/internal/imports/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/internal/imports/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/internal/prefilter/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/internal/prefilter/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/internal/prefilter/prefilter_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ func() uint32 = _prefilter

// _prefilter is only exported to the host.
//
//export prefilter
//go:wasmexport prefilter
func _prefilter() uint32 { //nolint
// This function begins a new scheduling cycle: zero out any cycle state.
currentPod = nil
Expand Down
2 changes: 1 addition & 1 deletion guest/klog/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/klog/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/klog/klog_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/postbind/postbind.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ func() = _postbind

// _postbind is only exported to the host.
//
//export postbind
//go:wasmexport postbind
func _postbind() { //nolint
if postbind == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/postfilter/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/postfilter/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/postfilter/postfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ func() uint64 = _postfilter

// _postfilter is only exported to the host.
//
//export postfilter
//go:wasmexport postfilter
func _postfilter() uint64 { //nolint

if postfilter == nil { // Then, the user didn't define one.
Expand Down
2 changes: 1 addition & 1 deletion guest/prebind/prebind.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ func() uint32 = _prebind

// _prebind is only exported to the host.
//
//export prebind
//go:wasmexport prebind
func _prebind() uint32 { //nolint
if prebind == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/prescore/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/prescore/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/prescore/prescore.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ func() uint32 = _prescore

// prescore is only exported to the host.
//
//export prescore
//go:wasmexport prescore
func _prescore() uint32 {
if prescore == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
4 changes: 2 additions & 2 deletions guest/reserve/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (

// _reserve is only exported to the host.
//
//export reserve
//go:wasmexport reserve
func _reserve() uint32 { //nolint
if reserve == nil { // Then, the user didn't define one.
// Unlike most plugins we always export reserve so that we can reset
Expand All @@ -77,7 +77,7 @@ func _reserve() uint32 { //nolint

// _unreserve is only exported to the host.
//
//export unreserve
//go:wasmexport unreserve
func _unreserve() { //nolint
if reserve == nil { // Then, the user didn't define one.
// Unlike most plugins we always export unreserve so that we can reset
Expand Down
2 changes: 1 addition & 1 deletion guest/score/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ func() uint64 = _score

// score is only exported to the host.
//
//export score
//go:wasmexport score
func _score() uint64 {
if score == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
2 changes: 1 addition & 1 deletion guest/scoreextensions/imports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tinygo.wasm
//go:build wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/scoreextensions/imports_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !tinygo.wasm
//go:build !wasm

/*
Copyright 2023 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion guest/scoreextensions/scoreextensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ func() uint32 = _normalizescore

// normalizescore is only exported to the host.
//
//export normalizescore
//go:wasmexport normalizescore
func _normalizescore() uint32 {
if scoreextensions == nil { // Then, the user didn't define one.
// This is likely caused by use of plugin.Set(p), where 'p' didn't
Expand Down
3 changes: 2 additions & 1 deletion guest/testdata/bind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type extensionPoints interface {
api.PostBindPlugin
}

func main() {
func main() {}
func init() {
// Multiple tests are here to reduce re-compilation time and size checked
// into git.
var plugin extensionPoints = noopPlugin{}
Expand Down
Binary file modified guest/testdata/bind/main.wasm
100755 → 100644
Binary file not shown.
3 changes: 2 additions & 1 deletion guest/testdata/cyclestate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import (
protoapi "sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api"
)

func main() {
func main() {}
func init() {
// Multiple tests are here to reduce re-compilation time and size checked
// into git.
if len(os.Args) == 2 {
Expand Down
Binary file modified guest/testdata/cyclestate/main.wasm
100755 → 100644
Binary file not shown.
3 changes: 2 additions & 1 deletion guest/testdata/filter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type extensionPoints interface {
api.PreFilterExtensions
}

func main() {
func main() {}
func init() {
// Multiple tests are here to reduce re-compilation time and size checked
// into git.
var plugin extensionPoints = noopPlugin{}
Expand Down
Binary file modified guest/testdata/filter/main.wasm
100755 → 100644
Binary file not shown.
3 changes: 2 additions & 1 deletion guest/testdata/handle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type extensionPoints interface {
}

// This code is for checking the method of handle.
func main() {
func main() {}
func init() {
// Multiple tests are here to reduce re-compilation time and size checked
// into git.
var plugin extensionPoints = noopPlugin{}
Expand Down
Binary file modified guest/testdata/handle/main.wasm
100755 → 100644
Binary file not shown.
Loading
Loading