mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
fix bug: concurrent map writes error
This commit is contained in:
parent
8c7cd8a8cc
commit
42c00bc523
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@ -53,6 +54,7 @@ type stateData struct {
|
|||||||
// phase for each node
|
// phase for each node
|
||||||
// it's initialized in the PreFilter phase
|
// it's initialized in the PreFilter phase
|
||||||
podVolumesByNode map[string]*scheduling.PodVolumes
|
podVolumesByNode map[string]*scheduling.PodVolumes
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *stateData) Clone() framework.StateData {
|
func (d *stateData) Clone() framework.StateData {
|
||||||
@ -205,9 +207,10 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.Lock()
|
// multiple goroutines call `Filter` on different nodes simultaneously and the `CycleState` may be duplicated, so we must use a local lock here
|
||||||
|
state.Lock()
|
||||||
state.podVolumesByNode[node.Name] = podVolumes
|
state.podVolumesByNode[node.Name] = podVolumes
|
||||||
cs.Unlock()
|
state.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user