mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
527 making status listner into a buffered channel instead of go routines
This commit is contained in:
parent
fdb1cc36ac
commit
38b92a0d34
7 changed files with 12 additions and 28 deletions
|
@ -127,12 +127,10 @@ func (c *Controller) applyGeneratePolicy(policyContext engine.PolicyContext, gr
|
|||
}
|
||||
|
||||
if gr.Status.State == "" {
|
||||
go func() {
|
||||
c.policyStatus.Listener <- &generateSyncStats{
|
||||
policyName: policy.Name,
|
||||
ruleNameToProcessingTime: ruleNameToProcessingTime,
|
||||
}
|
||||
}()
|
||||
c.policyStatus.Listener <- &generateSyncStats{
|
||||
policyName: policy.Name,
|
||||
ruleNameToProcessingTime: ruleNameToProcessingTime,
|
||||
}
|
||||
}
|
||||
|
||||
return genResources, nil
|
||||
|
|
|
@ -41,7 +41,7 @@ func NewSync(c *versioned.Clientset, p policyStore) *Sync {
|
|||
},
|
||||
client: c,
|
||||
PolicyStore: p,
|
||||
Listener: make(chan statusUpdater),
|
||||
Listener: make(chan statusUpdater, 20),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,9 +100,7 @@ func (cpv *clusterPV) createPV(newPv *kyverno.ClusterPolicyViolation) error {
|
|||
}
|
||||
|
||||
if newPv.Annotations["fromSync"] != "true" {
|
||||
go func() {
|
||||
cpv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}()
|
||||
cpv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}
|
||||
|
||||
glog.Infof("policy violation created for resource %v", newPv.Spec.ResourceSpec)
|
||||
|
@ -128,9 +126,7 @@ func (cpv *clusterPV) updatePV(newPv, oldPv *kyverno.ClusterPolicyViolation) err
|
|||
glog.Infof("cluster policy violation updated for resource %v", newPv.Spec.ResourceSpec)
|
||||
|
||||
if newPv.Annotations["fromSync"] != "true" {
|
||||
go func() {
|
||||
cpv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}()
|
||||
cpv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -99,9 +99,7 @@ func (nspv *namespacedPV) createPV(newPv *kyverno.PolicyViolation) error {
|
|||
}
|
||||
|
||||
if newPv.Annotations["fromSync"] != "true" {
|
||||
go func() {
|
||||
nspv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}()
|
||||
nspv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}
|
||||
glog.Infof("policy violation created for resource %v", newPv.Spec.ResourceSpec)
|
||||
return nil
|
||||
|
@ -124,9 +122,7 @@ func (nspv *namespacedPV) updatePV(newPv, oldPv *kyverno.PolicyViolation) error
|
|||
}
|
||||
|
||||
if newPv.Annotations["fromSync"] != "true" {
|
||||
go func() {
|
||||
nspv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}()
|
||||
nspv.policyStatus.Listener <- updatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
|
||||
}
|
||||
glog.Infof("namespaced policy violation updated for resource %v", newPv.Spec.ResourceSpec)
|
||||
return nil
|
||||
|
|
|
@ -68,9 +68,7 @@ func (ws *WebhookServer) HandleGenerate(request *v1beta1.AdmissionRequest, polic
|
|||
if len(engineResponse.PolicyResponse.Rules) > 0 {
|
||||
// some generate rules do apply to the resource
|
||||
engineResponses = append(engineResponses, engineResponse)
|
||||
go func() {
|
||||
ws.status.Listener <- updateStatusWithGenerateStats(engineResponse)
|
||||
}()
|
||||
ws.status.Listener <- updateStatusWithGenerateStats(engineResponse)
|
||||
}
|
||||
}
|
||||
// Adds Generate Request to a channel(queue size 1000) to generators
|
||||
|
|
|
@ -63,9 +63,7 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
|
|||
policyContext.Policy = policy
|
||||
engineResponse := engine.Mutate(policyContext)
|
||||
engineResponses = append(engineResponses, engineResponse)
|
||||
go func() {
|
||||
ws.status.Listener <- updateStatusWithMutateStats(engineResponse)
|
||||
}()
|
||||
ws.status.Listener <- updateStatusWithMutateStats(engineResponse)
|
||||
if !engineResponse.IsSuccesful() {
|
||||
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName())
|
||||
continue
|
||||
|
|
|
@ -73,9 +73,7 @@ func (ws *WebhookServer) HandleValidation(request *v1beta1.AdmissionRequest, pol
|
|||
continue
|
||||
}
|
||||
engineResponses = append(engineResponses, engineResponse)
|
||||
go func() {
|
||||
ws.status.Listener <- updateStatusWithValidateStats(engineResponse)
|
||||
}()
|
||||
ws.status.Listener <- updateStatusWithValidateStats(engineResponse)
|
||||
if !engineResponse.IsSuccesful() {
|
||||
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, newR.GetNamespace(), newR.GetName())
|
||||
continue
|
||||
|
|
Loading…
Add table
Reference in a new issue