forget the pod when the reserve plugins fail

and move the metrics function calls before all other functions
This commit is contained in:
Yecheng Fu
2020-08-09 20:28:23 +08:00
parent 9b78bd5979
commit 1176ef9c7d
4 changed files with 157 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ import (
"context"
"fmt"
"sync/atomic"
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -152,3 +153,81 @@ func NewFakePreFilterPlugin(status *framework.Status) frameworkruntime.PluginFac
}, nil
}
}
// FakeReservePlugin is a test reserve plugin.
type FakeReservePlugin struct {
Status *framework.Status
}
// Name returns name of the plugin.
func (pl *FakeReservePlugin) Name() string {
return "FakeReserve"
}
// Reserve invoked at the Reserve extension point.
func (pl *FakeReservePlugin) Reserve(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) *framework.Status {
return pl.Status
}
// Unreserve invoked at the Unreserve extension point.
func (pl *FakeReservePlugin) Unreserve(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) {
}
// NewFakeReservePlugin initializes a fakeReservePlugin and returns it.
func NewFakeReservePlugin(status *framework.Status) frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &FakeReservePlugin{
Status: status,
}, nil
}
}
// FakePreBindPlugin is a test prebind plugin.
type FakePreBindPlugin struct {
Status *framework.Status
}
// Name returns name of the plugin.
func (pl *FakePreBindPlugin) Name() string {
return "FakePreBind"
}
// PreBind invoked at the PreBind extension point.
func (pl *FakePreBindPlugin) PreBind(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) *framework.Status {
return pl.Status
}
// NewFakePreBindPlugin initializes a fakePreBindPlugin and returns it.
func NewFakePreBindPlugin(status *framework.Status) frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &FakePreBindPlugin{
Status: status,
}, nil
}
}
// FakePermitPlugin is a test permit plugin.
type FakePermitPlugin struct {
Status *framework.Status
Timeout time.Duration
}
// Name returns name of the plugin.
func (pl *FakePermitPlugin) Name() string {
return "FakePermit"
}
// Permit invoked at the Permit extension point.
func (pl *FakePermitPlugin) Permit(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) (*framework.Status, time.Duration) {
return pl.Status, pl.Timeout
}
// NewFakePermitPlugin initializes a fakePermitPlugin and returns it.
func NewFakePermitPlugin(status *framework.Status, timeout time.Duration) frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &FakePermitPlugin{
Status: status,
Timeout: timeout,
}, nil
}
}

View File

@@ -52,6 +52,21 @@ func RegisterFilterPlugin(pluginName string, pluginNewFunc runtime.PluginFactory
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Filter")
}
// RegisterReservePlugin returns a function to register a Reserve Plugin to a given registry.
func RegisterReservePlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Reserve")
}
// RegisterPermitPlugin returns a function to register a Permit Plugin to a given registry.
func RegisterPermitPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Permit")
}
// RegisterPreBindPlugin returns a function to register a PreBind Plugin to a given registry.
func RegisterPreBindPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "PreBind")
}
// RegisterScorePlugin returns a function to register a Score Plugin to a given registry.
func RegisterScorePlugin(pluginName string, pluginNewFunc runtime.PluginFactory, weight int32) RegisterPluginFunc {
return RegisterPluginAsExtensionsWithWeight(pluginName, weight, pluginNewFunc, "Score")