generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add api.Plugin as a base type for guest plugins
This adds `api.Plugin` as a base type for guest plugins. This is similar to `framework.Plugin`, but doesn't yet define `Name()` as there's no purpose for it. Notes on that are added to RATIONALE.md. This mostly gets the guest SDK looking much more like the framework one. This also makes it easier to test for misconfiguration, such as registering multiple instances of plugins. Signed-off-by: Adrian Cole <adrian@tetrate.io>
- Loading branch information
Adrian Cole
committed
Jul 12, 2023
1 parent
73c8b13
commit d39d13c
Showing
34 changed files
with
356 additions
and
238 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
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
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 was deleted.
Oops, something went wrong.
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,42 @@ | ||
/* | ||
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 plugin includes utilities needed for any api.Plugin. | ||
package plugin | ||
|
||
import ( | ||
"reflect" | ||
|
||
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api" | ||
) | ||
|
||
var current api.Plugin | ||
|
||
// MustSet sets the plugin once | ||
func MustSet(plugin api.Plugin) { | ||
if !set(plugin) { | ||
panic("only one plugin instance is supported") | ||
} | ||
} | ||
|
||
func set(plugin api.Plugin) bool { | ||
if current == nil { | ||
current = plugin | ||
return true | ||
} | ||
// current == plugin with the same value works in Go, but not TinyGo. | ||
return reflect.DeepEqual(current, plugin) | ||
} |
Oops, something went wrong.