Skip to content

Commit e45f92f

Browse files
authored
Merge pull request kubernetes#77626 from ahg-g/ahg-mutex
Make thread-safe the prebind callback of stateful plugin in scheduler…
2 parents 3ab338d + 7b12731 commit e45f92f

File tree

1 file changed

+6
-0
lines changed
  • pkg/scheduler/framework/plugins/examples/stateful

1 file changed

+6
-0
lines changed

pkg/scheduler/framework/plugins/examples/stateful/stateful.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package stateful
1818

1919
import (
2020
"fmt"
21+
"sync"
2122

2223
"k8s.io/api/core/v1"
2324
"k8s.io/apimachinery/pkg/runtime"
@@ -31,6 +32,7 @@ import (
3132
type MultipointExample struct {
3233
mpState map[int]string
3334
numRuns int
35+
mu sync.RWMutex
3436
}
3537

3638
var _ = framework.ReservePlugin(&MultipointExample{})
@@ -46,12 +48,16 @@ func (mp *MultipointExample) Name() string {
4648

4749
// Reserve is the functions invoked by the framework at "reserve" extension point.
4850
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.
4952
mp.numRuns++
5053
return nil
5154
}
5255

5356
// Prebind is the functions invoked by the framework at "prebind" extension point.
5457
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()
5561
mp.numRuns++
5662
if pod == nil {
5763
return framework.NewStatus(framework.Error, "pod must not be nil")

0 commit comments

Comments
 (0)