mirror of
https://github.com/kyverno/kyverno.git
synced 2025-01-20 18:52:16 +00:00
527 minor fixes
This commit is contained in:
parent
592df74c57
commit
ac37ec66f0
4 changed files with 18 additions and 6 deletions
|
@ -2,6 +2,7 @@ package policy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -118,6 +119,10 @@ func (s *StatSync) UpdateStatusWithMutateStats(response response.EngineResponse)
|
||||||
ruleStats = append(ruleStats, ruleStat)
|
ruleStats = append(ruleStats, ruleStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(ruleStats, func(i, j int) bool {
|
||||||
|
return ruleStats[i].Name < ruleStats[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
||||||
policyStatus.Rules = ruleStats
|
policyStatus.Rules = ruleStats
|
||||||
|
|
||||||
|
@ -154,13 +159,13 @@ func (s *StatSync) UpdateStatusWithValidateStats(response response.EngineRespons
|
||||||
if rule.Success {
|
if rule.Success {
|
||||||
policyStatus.RulesAppliedCount++
|
policyStatus.RulesAppliedCount++
|
||||||
ruleStat.AppliedCount++
|
ruleStat.AppliedCount++
|
||||||
|
} else {
|
||||||
|
policyStatus.ViolationCount++
|
||||||
|
ruleStat.ViolationCount++
|
||||||
if response.PolicyResponse.ValidationFailureAction == "enforce" {
|
if response.PolicyResponse.ValidationFailureAction == "enforce" {
|
||||||
policyStatus.ResourcesBlockedCount++
|
policyStatus.ResourcesBlockedCount++
|
||||||
ruleStat.ResourcesBlockedCount++
|
ruleStat.ResourcesBlockedCount++
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
policyStatus.ViolationCount++
|
|
||||||
ruleStat.ViolationCount++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nameToRule[rule.Name] = ruleStat
|
nameToRule[rule.Name] = ruleStat
|
||||||
|
@ -176,6 +181,10 @@ func (s *StatSync) UpdateStatusWithValidateStats(response response.EngineRespons
|
||||||
ruleStats = append(ruleStats, ruleStat)
|
ruleStats = append(ruleStats, ruleStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(ruleStats, func(i, j int) bool {
|
||||||
|
return ruleStats[i].Name < ruleStats[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
||||||
policyStatus.Rules = ruleStats
|
policyStatus.Rules = ruleStats
|
||||||
|
|
||||||
|
@ -230,6 +239,10 @@ func (s *StatSync) UpdateStatusWithGenerateStats(response response.EngineRespons
|
||||||
ruleStats = append(ruleStats, ruleStat)
|
ruleStats = append(ruleStats, ruleStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(ruleStats, func(i, j int) bool {
|
||||||
|
return ruleStats[i].Name < ruleStats[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
policyStatus.AvgExecutionTime = policyAverageExecutionTime.String()
|
||||||
policyStatus.Rules = ruleStats
|
policyStatus.Rules = ruleStats
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ func (ws *WebhookServer) HandleGenerate(request *v1beta1.AdmissionRequest, polic
|
||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
policyContext.Policy = policy
|
policyContext.Policy = policy
|
||||||
engineResponse := engine.Generate(policyContext)
|
engineResponse := engine.Generate(policyContext)
|
||||||
go ws.status.UpdateStatusWithGenerateStats(engineResponse)
|
|
||||||
if len(engineResponse.PolicyResponse.Rules) > 0 {
|
if len(engineResponse.PolicyResponse.Rules) > 0 {
|
||||||
// some generate rules do apply to the resource
|
// some generate rules do apply to the resource
|
||||||
engineResponses = append(engineResponses, engineResponse)
|
engineResponses = append(engineResponses, engineResponse)
|
||||||
|
|
|
@ -62,11 +62,11 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
|
||||||
}
|
}
|
||||||
engineResponse := engine.Mutate(policyContext)
|
engineResponse := engine.Mutate(policyContext)
|
||||||
engineResponses = append(engineResponses, engineResponse)
|
engineResponses = append(engineResponses, engineResponse)
|
||||||
|
go ws.status.UpdateStatusWithMutateStats(engineResponse)
|
||||||
if !engineResponse.IsSuccesful() {
|
if !engineResponse.IsSuccesful() {
|
||||||
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName())
|
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go ws.status.UpdateStatusWithMutateStats(engineResponse)
|
|
||||||
// gather patches
|
// gather patches
|
||||||
patches = append(patches, engineResponse.GetPatches()...)
|
patches = append(patches, engineResponse.GetPatches()...)
|
||||||
glog.V(4).Infof("Mutation from policy %s has applied successfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())
|
glog.V(4).Infof("Mutation from policy %s has applied successfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())
|
||||||
|
|
|
@ -69,11 +69,11 @@ func (ws *WebhookServer) HandleValidation(request *v1beta1.AdmissionRequest, pol
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
engineResponses = append(engineResponses, engineResponse)
|
engineResponses = append(engineResponses, engineResponse)
|
||||||
|
go ws.status.UpdateStatusWithValidateStats(engineResponse)
|
||||||
if !engineResponse.IsSuccesful() {
|
if !engineResponse.IsSuccesful() {
|
||||||
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, newR.GetNamespace(), newR.GetName())
|
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, newR.GetNamespace(), newR.GetName())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go ws.status.UpdateStatusWithValidateStats(engineResponse)
|
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("eval: %v %s/%s/%s ", time.Since(evalTime), request.Kind, request.Namespace, request.Name)
|
glog.V(4).Infof("eval: %v %s/%s/%s ", time.Since(evalTime), request.Kind, request.Namespace, request.Name)
|
||||||
// report time
|
// report time
|
||||||
|
|
Loading…
Add table
Reference in a new issue