mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Fix data race in PVC Run/Stop methods
This commit is contained in:
@@ -154,13 +154,10 @@ const createProvisionedPVInterval = 10 * time.Second
|
||||
// changes.
|
||||
type PersistentVolumeController struct {
|
||||
volumeController *framework.Controller
|
||||
volumeControllerStopCh chan struct{}
|
||||
volumeSource cache.ListerWatcher
|
||||
claimController *framework.Controller
|
||||
claimControllerStopCh chan struct{}
|
||||
claimSource cache.ListerWatcher
|
||||
classReflector *cache.Reflector
|
||||
classReflectorStopCh chan struct{}
|
||||
classSource cache.ListerWatcher
|
||||
kubeClient clientset.Interface
|
||||
eventRecorder record.EventRecorder
|
||||
|
||||
@@ -442,33 +442,12 @@ func (ctrl *PersistentVolumeController) deleteClaim(obj interface{}) {
|
||||
}
|
||||
|
||||
// Run starts all of this controller's control loops
|
||||
func (ctrl *PersistentVolumeController) Run() {
|
||||
func (ctrl *PersistentVolumeController) Run(stopCh <-chan struct{}) {
|
||||
glog.V(4).Infof("starting PersistentVolumeController")
|
||||
|
||||
ctrl.initializeCaches(ctrl.volumeSource, ctrl.claimSource)
|
||||
|
||||
if ctrl.volumeControllerStopCh == nil {
|
||||
ctrl.volumeControllerStopCh = make(chan struct{})
|
||||
go ctrl.volumeController.Run(ctrl.volumeControllerStopCh)
|
||||
}
|
||||
|
||||
if ctrl.claimControllerStopCh == nil {
|
||||
ctrl.claimControllerStopCh = make(chan struct{})
|
||||
go ctrl.claimController.Run(ctrl.claimControllerStopCh)
|
||||
}
|
||||
|
||||
if ctrl.classReflectorStopCh == nil {
|
||||
ctrl.classReflectorStopCh = make(chan struct{})
|
||||
go ctrl.classReflector.RunUntil(ctrl.classReflectorStopCh)
|
||||
}
|
||||
}
|
||||
|
||||
// Stop gracefully shuts down this controller
|
||||
func (ctrl *PersistentVolumeController) Stop() {
|
||||
glog.V(4).Infof("stopping PersistentVolumeController")
|
||||
close(ctrl.volumeControllerStopCh)
|
||||
close(ctrl.claimControllerStopCh)
|
||||
close(ctrl.classReflectorStopCh)
|
||||
go ctrl.volumeController.Run(stopCh)
|
||||
go ctrl.claimController.Run(stopCh)
|
||||
go ctrl.classReflector.RunUntil(stopCh)
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -175,7 +175,8 @@ func TestControllerSync(t *testing.T) {
|
||||
}
|
||||
|
||||
// Start the controller
|
||||
go ctrl.Run()
|
||||
stopCh := make(chan struct{})
|
||||
ctrl.Run(stopCh)
|
||||
|
||||
// Wait for the controller to pass initial sync and fill its caches.
|
||||
for !ctrl.volumeController.HasSynced() ||
|
||||
@@ -201,7 +202,7 @@ func TestControllerSync(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Failed to run test %s: %v", test.name, err)
|
||||
}
|
||||
ctrl.Stop()
|
||||
close(stopCh)
|
||||
|
||||
evaluateTestResults(ctrl, reactor, test, t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user