feat(scheduler): rename PluginContext to CycleState
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
// CommunicatingPlugin is an example of a plugin that implements two
|
||||
// extension points. It communicates through pluginContext with another function.
|
||||
// extension points. It communicates through state with another function.
|
||||
type CommunicatingPlugin struct{}
|
||||
|
||||
var _ = framework.ReservePlugin(CommunicatingPlugin{})
|
||||
@@ -37,39 +37,39 @@ func (mc CommunicatingPlugin) Name() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
type contextData struct {
|
||||
type stateData struct {
|
||||
data string
|
||||
}
|
||||
|
||||
func (f *contextData) Clone() framework.ContextData {
|
||||
copy := &contextData{
|
||||
func (f *stateData) Clone() framework.StateData {
|
||||
copy := &stateData{
|
||||
data: f.data,
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
||||
// Reserve is the functions invoked by the framework at "reserve" extension point.
|
||||
func (mc CommunicatingPlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
func (mc CommunicatingPlugin) Reserve(state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
if pod == nil {
|
||||
return framework.NewStatus(framework.Error, "pod cannot be nil")
|
||||
}
|
||||
if pod.Name == "my-test-pod" {
|
||||
pc.Lock()
|
||||
pc.Write(framework.ContextKey(pod.Name), &contextData{data: "never bind"})
|
||||
pc.Unlock()
|
||||
state.Lock()
|
||||
state.Write(framework.StateKey(pod.Name), &stateData{data: "never bind"})
|
||||
state.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PreBind is the functions invoked by the framework at "prebind" extension point.
|
||||
func (mc CommunicatingPlugin) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
func (mc CommunicatingPlugin) PreBind(state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
if pod == nil {
|
||||
return framework.NewStatus(framework.Error, "pod cannot be nil")
|
||||
}
|
||||
pc.RLock()
|
||||
defer pc.RUnlock()
|
||||
if v, e := pc.Read(framework.ContextKey(pod.Name)); e == nil {
|
||||
if value, ok := v.(*contextData); ok && value.data == "never bind" {
|
||||
state.RLock()
|
||||
defer state.RUnlock()
|
||||
if v, e := state.Read(framework.StateKey(pod.Name)); e == nil {
|
||||
if value, ok := v.(*stateData); ok && value.data == "never bind" {
|
||||
return framework.NewStatus(framework.Unschedulable, "pod is not permitted")
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ func (sr StatelessPreBindExample) Name() string {
|
||||
}
|
||||
|
||||
// PreBind is the functions invoked by the framework at "prebind" extension point.
|
||||
func (sr StatelessPreBindExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
func (sr StatelessPreBindExample) PreBind(state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
if pod == nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("pod cannot be nil"))
|
||||
}
|
||||
|
@@ -47,14 +47,14 @@ func (mp *MultipointExample) Name() string {
|
||||
}
|
||||
|
||||
// Reserve is the functions invoked by the framework at "reserve" extension point.
|
||||
func (mp *MultipointExample) Reserve(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
func (mp *MultipointExample) Reserve(state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
// Reserve is not called concurrently, and so we don't need to lock.
|
||||
mp.numRuns++
|
||||
return nil
|
||||
}
|
||||
|
||||
// PreBind is the functions invoked by the framework at "prebind" extension point.
|
||||
func (mp *MultipointExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
func (mp *MultipointExample) PreBind(state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
|
||||
// PreBind could be called concurrently for different pods.
|
||||
mp.mu.Lock()
|
||||
defer mp.mu.Unlock()
|
||||
|
Reference in New Issue
Block a user