From a371f3ba8e10955ddc5c5ba510d2984eec199cba Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Mon, 15 Jan 2018 15:39:12 -0500 Subject: [PATCH] Track run status explicitly rather than non-nil check on stopCh --- cmd/kube-controller-manager/app/controllermanager.go | 4 +--- pkg/controller/garbagecollector/graph_builder.go | 12 +++++++----- .../resourcequota/resource_quota_monitor.go | 12 +++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/kube-controller-manager/app/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go index 25de45f504..664acf362f 100644 --- a/cmd/kube-controller-manager/app/controllermanager.go +++ b/cmd/kube-controller-manager/app/controllermanager.go @@ -171,9 +171,7 @@ func Run(s *options.CMServer) error { } if !s.LeaderElection.LeaderElect { - stopCh := make(chan struct{}) - defer close(stopCh) - run(stopCh) + run(wait.NeverStop) panic("unreachable") } diff --git a/pkg/controller/garbagecollector/graph_builder.go b/pkg/controller/garbagecollector/graph_builder.go index 56afc5f5ce..190938b0af 100644 --- a/pkg/controller/garbagecollector/graph_builder.go +++ b/pkg/controller/garbagecollector/graph_builder.go @@ -83,13 +83,14 @@ type GraphBuilder struct { // After that it is safe to start them here, before that it is not. informersStarted <-chan struct{} - // stopCh drives shutdown. If it is nil, it indicates that Run() has not been - // called yet. If it is non-nil, then when closed it indicates everything - // should shut down. - // + // stopCh drives shutdown. When a receive from it unblocks, monitors will shut down. // This channel is also protected by monitorLock. stopCh <-chan struct{} + // running tracks whether Run() has been called. + // it is protected by monitorLock. + running bool + // metaOnlyClientPool uses a special codec, which removes fields except for // apiVersion, kind, and metadata during decoding. metaOnlyClientPool dynamic.ClientPool @@ -275,7 +276,7 @@ func (gb *GraphBuilder) startMonitors() { gb.monitorLock.Lock() defer gb.monitorLock.Unlock() - if gb.stopCh == nil { + if !gb.running { return } @@ -325,6 +326,7 @@ func (gb *GraphBuilder) Run(stopCh <-chan struct{}) { // Set up the stop channel. gb.monitorLock.Lock() gb.stopCh = stopCh + gb.running = true gb.monitorLock.Unlock() // Start monitors and begin change processing until the stop channel is diff --git a/pkg/controller/resourcequota/resource_quota_monitor.go b/pkg/controller/resourcequota/resource_quota_monitor.go index e5d6dc593f..a412e02ff4 100644 --- a/pkg/controller/resourcequota/resource_quota_monitor.go +++ b/pkg/controller/resourcequota/resource_quota_monitor.go @@ -74,13 +74,14 @@ type QuotaMonitor struct { // After that it is safe to start them here, before that it is not. informersStarted <-chan struct{} - // stopCh drives shutdown. If it is nil, it indicates that Run() has not been - // called yet. If it is non-nil, then when closed it indicates everything - // should shut down. - // + // stopCh drives shutdown. When a receive from it unblocks, monitors will shut down. // This channel is also protected by monitorLock. stopCh <-chan struct{} + // running tracks whether Run() has been called. + // it is protected by monitorLock. + running bool + // monitors are the producer of the resourceChanges queue resourceChanges workqueue.RateLimitingInterface @@ -241,7 +242,7 @@ func (qm *QuotaMonitor) startMonitors() { qm.monitorLock.Lock() defer qm.monitorLock.Unlock() - if qm.stopCh == nil { + if !qm.running { return } @@ -291,6 +292,7 @@ func (qm *QuotaMonitor) Run(stopCh <-chan struct{}) { // Set up the stop channel. qm.monitorLock.Lock() qm.stopCh = stopCh + qm.running = true qm.monitorLock.Unlock() // Start monitors and begin change processing until the stop channel is