diff --git a/definitions/install.yaml b/definitions/install.yaml index a4f2e544f8..b8950c12e6 100644 --- a/definitions/install.yaml +++ b/definitions/install.yaml @@ -20,6 +20,7 @@ spec: validation: openAPIV3Schema: properties: + status: {} spec: required: - rules diff --git a/definitions/install_debug.yaml b/definitions/install_debug.yaml index e9a1343482..d17c931004 100644 --- a/definitions/install_debug.yaml +++ b/definitions/install_debug.yaml @@ -20,6 +20,7 @@ spec: validation: openAPIV3Schema: properties: + status: {} spec: required: - rules diff --git a/pkg/api/kyverno/v1/types.go b/pkg/api/kyverno/v1/types.go index 29c44b4385..69605a0c05 100644 --- a/pkg/api/kyverno/v1/types.go +++ b/pkg/api/kyverno/v1/types.go @@ -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 diff --git a/pkg/generate/policyStatus_test.go b/pkg/generate/policyStatus_test.go index b0fa04b591..b465a8547b 100644 --- a/pkg/generate/policyStatus_test.go +++ b/pkg/generate/policyStatus_test.go @@ -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", diff --git a/pkg/policystatus/main.go b/pkg/policystatus/main.go index b21ff2e505..6e89d41b9b 100644 --- a/pkg/policystatus/main.go +++ b/pkg/policystatus/main.go @@ -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 } diff --git a/pkg/policystatus/status_test.go b/pkg/policystatus/status_test.go index 310852cf2f..c36f1a5c0f 100644 --- a/pkg/policystatus/status_test.go +++ b/pkg/policystatus/status_test.go @@ -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{}) diff --git a/pkg/policyviolation/policyStatus_test.go b/pkg/policyviolation/policyStatus_test.go index 8db26ae4a6..39f718ba13 100644 --- a/pkg/policyviolation/policyStatus_test.go +++ b/pkg/policyviolation/policyStatus_test.go @@ -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