generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from Gekko0114/postbind
Support postBind plugin
- Loading branch information
Showing
20 changed files
with
360 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
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 postbind exports an api.PostBindPlugin to the host. | ||
package postbind | ||
|
||
import ( | ||
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api" | ||
"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" | ||
) | ||
|
||
// postbind is the current plugin assigned with SetPlugin. | ||
var postbind api.PostBindPlugin | ||
|
||
// SetPlugin should be called in `main` to assign an api.PostBindPlugin | ||
// instance. | ||
// | ||
// For example: | ||
// | ||
// func main() { | ||
// plugin := bindPlugin{} | ||
// bind.SetPlugin(plugin) | ||
// postbind.SetPlugin(plugin) | ||
// } | ||
// | ||
// type bindPlugin struct{} | ||
// | ||
// func (bindPlugin) Bind(state api.CycleState, pod proto.Pod, nodeName string) (status *api.Status) { | ||
// // Write state you need on Bind | ||
// } | ||
// | ||
// func (bindPlugin) PostBind(state api.CycleState, pod proto.Pod, nodeName string) { | ||
// // Write state you need on PostBind | ||
// } | ||
func SetPlugin(postbindPlugin api.PostBindPlugin) { | ||
if postbindPlugin == nil { | ||
panic("nil postbindPlugin") | ||
} | ||
postbind = postbindPlugin | ||
plugin.MustSet(postbind) | ||
} | ||
|
||
// prevent unused lint errors (lint is run with normal go). | ||
var _ func() = _postbind | ||
|
||
// _postbind is only exported to the host. | ||
// | ||
//export 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 | ||
// implement PostBindPlugin: return success. | ||
return | ||
} | ||
|
||
nodeName := imports.NodeName() | ||
// The parameters passed are lazy with regard to host functions. This means | ||
// a no-op plugin should not have any unmarshal penalty. | ||
postbind.PostBind(cyclestate.Values, cyclestate.Pod, nodeName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.