1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

527 save commit

This commit is contained in:
shravan 2020-02-19 09:27:39 +05:30
parent b5e5f3eeda
commit e9fc19142a
2 changed files with 34 additions and 13 deletions
pkg
policy
webhooks

View file

@ -54,26 +54,26 @@ func newStatusCache() *statusCache {
func NewStatusSync(client *versioned.Clientset, stopCh <-chan struct{}) *StatusSync {
return &StatusSync{
statusReceiver: make(chan map[string]v1.PolicyStatus),
cache: newStatusCache(),
stop: stopCh,
client: client,
policyStatsReciever: make(chan map[string]v1.PolicyStatus),
cache: newStatusCache(),
stop: stopCh,
client: client,
}
}
type StatusSync struct {
statusReceiver chan map[string]v1.PolicyStatus
cache *statusCache
stop <-chan struct{}
client *versioned.Clientset
policyStatsReciever chan map[string]v1.PolicyStatus
cache *statusCache
stop <-chan struct{}
client *versioned.Clientset
}
func (s *StatusSync) Cache() *statusCache {
return s.cache
}
func (s *StatusSync) Receiver() chan<- map[string]v1.PolicyStatus {
return s.statusReceiver
func (s *StatusSync) StatReceiver() chan<- map[string]v1.PolicyStatus {
return s.policyStatsReciever
}
func (s *StatusSync) Start() {
@ -81,7 +81,7 @@ func (s *StatusSync) Start() {
go func() {
for {
select {
case nameToStatus := <-s.statusReceiver:
case nameToStatus := <-s.policyStatsReciever:
for policyName, status := range nameToStatus {
s.cache.Set(policyName, status)
}

View file

@ -110,6 +110,27 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
}
func updateStatusWithMutate(statusSync *policy.StatusSync, policy kyverno.ClusterPolicy, response response.EngineResponse) {
status := statusSync.Cache().Get(policy.Name)
status
stats := kyverno.PolicyStatus{
ViolationCount: 0,
RulesAppliedCount: response.PolicyResponse.RulesAppliedCount,
ResourcesBlockedCount: 0,
AvgExecutionTimeMutation: response.PolicyResponse.ProcessingTime.String(),
Rules: nil,
}
for _, rule := range response.PolicyResponse.Rules {
ruleStats := kyverno.RuleStats{
Name: rule.Name,
ExecutionTime: rule.ProcessingTime.String(),
AppliedCount: 0,
ViolationCount: 0,
MutationCount: 0,
}
if rule.Success {
ruleStats.AppliedCount++
ruleStats.MutationCount++
}
}
}