mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
527 stopCh changes
This commit is contained in:
parent
8c84e9af2b
commit
053ccde6b8
3 changed files with 10 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue