1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 07:26:55 +00:00

Merge pull request #809 from shravanshetty1/808_policy_status

#808 - Policy status is not being updated
This commit is contained in:
Shravan Shetty 2020-04-13 22:02:05 +05:30 committed by GitHub
commit 3a56a2d624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 6 deletions

View file

@ -20,6 +20,7 @@ spec:
validation:
openAPIV3Schema:
properties:
status: {}
spec:
required:
- rules

View file

@ -20,6 +20,7 @@ spec:
validation:
openAPIV3Schema:
properties:
status: {}
spec:
required:
- rules

View file

@ -121,7 +121,7 @@ type Policy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec Spec `json:"spec"`
Status PolicyStatus `json:"status"`
Status PolicyStatus `json:"status,omitempty"`
}
// Spec describes policy behavior by its rules
@ -230,7 +230,7 @@ type CloneFrom struct {
// PolicyStatus mostly contains statistics related to policy
type PolicyStatus struct {
// average time required to process the policy rules on a resource
AvgExecutionTime string `json:"averageExecutionTime"`
AvgExecutionTime string `json:"averageExecutionTime,omitempty"`
// number of violations created by this policy
ViolationCount int `json:"violationCount,omitempty"`
// Count of rules that failed

View file

@ -15,7 +15,7 @@ func Test_Stats(t *testing.T) {
expectedOutput []byte
existingStatus map[string]v1.PolicyStatus
}{
expectedOutput: []byte(`{"policy1":{"averageExecutionTime":"","resourcesGeneratedCount":2,"ruleStatus":[{"ruleName":"rule1","averageExecutionTime":"23ns","resourcesGeneratedCount":1},{"ruleName":"rule2","averageExecutionTime":"44ns","resourcesGeneratedCount":1},{"ruleName":"rule3"}]}}`),
expectedOutput: []byte(`{"policy1":{"resourcesGeneratedCount":2,"ruleStatus":[{"ruleName":"rule1","averageExecutionTime":"23ns","resourcesGeneratedCount":1},{"ruleName":"rule2","averageExecutionTime":"44ns","resourcesGeneratedCount":1},{"ruleName":"rule3"}]}}`),
generatedSyncStats: []generateSyncStats{
{
policyName: "policy1",

View file

@ -80,7 +80,7 @@ func (s *Sync) Run(workers int, stopCh <-chan struct{}) {
go s.updateStatusCache(stopCh)
}
wait.Until(s.updatePolicyStatus, 2*time.Second, stopCh)
wait.Until(s.updatePolicyStatus, 10*time.Second, stopCh)
<-stopCh
}

View file

@ -28,7 +28,7 @@ func (d dummyStatusUpdater) PolicyName() string {
}
func TestKeyToMutex(t *testing.T) {
expectedCache := `{"policy1":{"averageExecutionTime":"","rulesAppliedCount":100}}`
expectedCache := `{"policy1":{"rulesAppliedCount":100}}`
stopCh := make(chan struct{})
s := NewSync(nil, dummyStore{})

View file

@ -33,7 +33,7 @@ func Test_Stats(t *testing.T) {
},
},
},
expectedOutput: []byte(`{"policy1":{"averageExecutionTime":"","violationCount":1,"ruleStatus":[{"ruleName":"rule4","violationCount":1}]},"policy2":{"averageExecutionTime":"","violationCount":1,"ruleStatus":[{"ruleName":"rule4","violationCount":1}]}}`),
expectedOutput: []byte(`{"policy1":{"violationCount":1,"ruleStatus":[{"ruleName":"rule4","violationCount":1}]},"policy2":{"violationCount":1,"ruleStatus":[{"ruleName":"rule4","violationCount":1}]}}`),
violationCountStats: []struct {
policyName string
violatedRules []v1.ViolatedRule