File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
pkg/scheduler/framework/plugins/examples/stateful Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package stateful
18
18
19
19
import (
20
20
"fmt"
21
+ "sync"
21
22
22
23
"k8s.io/api/core/v1"
23
24
"k8s.io/apimachinery/pkg/runtime"
@@ -31,6 +32,7 @@ import (
31
32
type MultipointExample struct {
32
33
mpState map [int ]string
33
34
numRuns int
35
+ mu sync.RWMutex
34
36
}
35
37
36
38
var _ = framework .ReservePlugin (& MultipointExample {})
@@ -46,12 +48,16 @@ func (mp *MultipointExample) Name() string {
46
48
47
49
// Reserve is the functions invoked by the framework at "reserve" extension point.
48
50
func (mp * MultipointExample ) Reserve (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) * framework.Status {
51
+ // Reserve is not called concurrently, and so we don't need to lock.
49
52
mp .numRuns ++
50
53
return nil
51
54
}
52
55
53
56
// Prebind is the functions invoked by the framework at "prebind" extension point.
54
57
func (mp * MultipointExample ) Prebind (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) * framework.Status {
58
+ // Prebind could be called concurrently for different pods.
59
+ mp .mu .Lock ()
60
+ defer mp .mu .Unlock ()
55
61
mp .numRuns ++
56
62
if pod == nil {
57
63
return framework .NewStatus (framework .Error , "pod must not be nil" )
You can’t perform that action at this time.
0 commit comments