From 053ccde6b872af52ec74d57eb632e7c4e8296767 Mon Sep 17 00:00:00 2001 From: shravan Date: Sat, 29 Feb 2020 17:19:00 +0530 Subject: [PATCH] 527 stopCh changes --- cmd/kyverno/main.go | 2 +- pkg/generate/status.go | 4 ++-- pkg/policyStatus/0_main.go | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/kyverno/main.go b/cmd/kyverno/main.go index b60ebc77cb..261787cca8 100644 --- a/cmd/kyverno/main.go +++ b/cmd/kyverno/main.go @@ -248,7 +248,7 @@ func main() { go grc.Run(1, stopCh) go grcc.Run(1, stopCh) go pvgen.Run(1, stopCh) - go statusSync.Run(2) + go statusSync.Run(1, stopCh) // verifys if the admission control is enabled and active // resync: 60 seconds diff --git a/pkg/generate/status.go b/pkg/generate/status.go index b4c5b2c12c..f685800dd1 100644 --- a/pkg/generate/status.go +++ b/pkg/generate/status.go @@ -36,14 +36,14 @@ func (sc StatusControl) Failed(gr kyverno.GenerateRequest, message string, genRe // Success sets the gr status.state to completed and clears message func (sc StatusControl) Success(gr kyverno.GenerateRequest, genResources []kyverno.ResourceSpec) error { - grCopy := gr.DeepCopy() + oldState := gr.Status.State gr.Status.State = kyverno.Completed gr.Status.Message = "" // Update Generated Resources gr.Status.GeneratedResources = genResources - if grCopy.Status.State != kyverno.Completed { + if oldState != kyverno.Completed { go sc.policyStatus.UpdatePolicyStatusWithGeneratedResourceCount(gr) } diff --git a/pkg/policyStatus/0_main.go b/pkg/policyStatus/0_main.go index 5357a90252..991595cb08 100644 --- a/pkg/policyStatus/0_main.go +++ b/pkg/policyStatus/0_main.go @@ -18,7 +18,6 @@ import ( type Sync struct { cache *cache listener chan statusUpdater - stop <-chan struct{} client *versioned.Clientset policyStore *policystore.PolicyStore } @@ -28,35 +27,34 @@ type cache struct { data map[string]v1.PolicyStatus } -func NewSync(c *versioned.Clientset, sc <-chan struct{}, pms *policystore.PolicyStore) *Sync { +func NewSync(c *versioned.Clientset, pms *policystore.PolicyStore) *Sync { return &Sync{ cache: &cache{ mutex: sync.RWMutex{}, data: make(map[string]v1.PolicyStatus), }, - stop: sc, client: c, policyStore: pms, listener: make(chan statusUpdater), } } -func (s *Sync) Run(workers int) { +func (s *Sync) Run(workers int, stopCh <-chan struct{}) { for i := 0; i < workers; i++ { - go s.updateStatusCache() + go s.updateStatusCache(stopCh) } - wait.Until(s.updatePolicyStatus, 2*time.Second, s.stop) - <-s.stop + wait.Until(s.updatePolicyStatus, 2*time.Second, stopCh) + <-stopCh s.updatePolicyStatus() } -func (s *Sync) updateStatusCache() { +func (s *Sync) updateStatusCache(stopCh <-chan struct{}) { for { select { case statusUpdater := <-s.listener: statusUpdater.updateStatus() - case <-s.stop: + case <-stopCh: return } }