From e5c5cb39a08788d17c7a85111f45c6979807dc88 Mon Sep 17 00:00:00 2001 From: Shuting Zhao Date: Fri, 30 Oct 2020 18:01:46 -0700 Subject: [PATCH] update summary.* to lower case --- charts/kyverno/crds/crds.yaml | 120 +++++++------- .../policy.k8s.io_clusterpolicyreports.yaml | 30 ++-- ...cy.k8s.io_clusterreportchangerequests.yaml | 30 ++-- .../crds/policy.k8s.io_policyreports.yaml | 30 ++-- .../policy.k8s.io_reportchangerequests.yaml | 30 ++-- definitions/install.yaml | 120 +++++++------- definitions/install_debug.yaml | 120 +++++++------- .../v1alpha1/clusterpolicyreport_types.go | 10 +- .../clusterreportchangerequest_types.go | 10 +- .../v1alpha1/policyreport_types.go | 42 ++--- .../v1alpha1/reportchangerequest_types.go | 10 +- pkg/kyverno/apply/generate.go | 26 +-- pkg/kyverno/apply/generate_test.go | 35 ++-- pkg/kyverno/apply/report_test.go | 152 ++---------------- pkg/policyreport/builder.go | 1 + 15 files changed, 321 insertions(+), 445 deletions(-) diff --git a/charts/kyverno/crds/crds.yaml b/charts/kyverno/crds/crds.yaml index 67f0066f6f..d564196fc8 100644 --- a/charts/kyverno/crds/crds.yaml +++ b/charts/kyverno/crds/crds.yaml @@ -288,19 +288,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -482,11 +482,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -572,23 +572,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -695,19 +695,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -887,11 +887,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -977,23 +977,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1351,19 +1351,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1544,11 +1544,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -1634,23 +1634,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1757,19 +1757,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1949,11 +1949,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -2039,23 +2039,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/crds/policy.k8s.io_clusterpolicyreports.yaml b/definitions/crds/policy.k8s.io_clusterpolicyreports.yaml index 8de83d5524..1044e7bd74 100644 --- a/definitions/crds/policy.k8s.io_clusterpolicyreports.yaml +++ b/definitions/crds/policy.k8s.io_clusterpolicyreports.yaml @@ -17,19 +17,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -211,11 +211,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -301,23 +301,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/crds/policy.k8s.io_clusterreportchangerequests.yaml b/definitions/crds/policy.k8s.io_clusterreportchangerequests.yaml index 7482281d36..7b58425002 100644 --- a/definitions/crds/policy.k8s.io_clusterreportchangerequests.yaml +++ b/definitions/crds/policy.k8s.io_clusterreportchangerequests.yaml @@ -17,19 +17,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -209,11 +209,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -299,23 +299,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/crds/policy.k8s.io_policyreports.yaml b/definitions/crds/policy.k8s.io_policyreports.yaml index aaf618ca1d..e13c7991a7 100644 --- a/definitions/crds/policy.k8s.io_policyreports.yaml +++ b/definitions/crds/policy.k8s.io_policyreports.yaml @@ -17,19 +17,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -210,11 +210,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -300,23 +300,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/crds/policy.k8s.io_reportchangerequests.yaml b/definitions/crds/policy.k8s.io_reportchangerequests.yaml index a9dfae563e..58b78e7b76 100644 --- a/definitions/crds/policy.k8s.io_reportchangerequests.yaml +++ b/definitions/crds/policy.k8s.io_reportchangerequests.yaml @@ -17,19 +17,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -209,11 +209,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -299,23 +299,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/install.yaml b/definitions/install.yaml index 19752f5a3c..8ba10c7331 100755 --- a/definitions/install.yaml +++ b/definitions/install.yaml @@ -293,19 +293,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -487,11 +487,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -577,23 +577,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -700,19 +700,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -892,11 +892,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -982,23 +982,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1356,19 +1356,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1549,11 +1549,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -1639,23 +1639,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1762,19 +1762,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1954,11 +1954,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -2044,23 +2044,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/definitions/install_debug.yaml b/definitions/install_debug.yaml index 83bc629e1b..77b08608df 100755 --- a/definitions/install_debug.yaml +++ b/definitions/install_debug.yaml @@ -293,19 +293,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -487,11 +487,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -577,23 +577,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -700,19 +700,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -892,11 +892,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -982,23 +982,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1356,19 +1356,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1549,11 +1549,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -1639,23 +1639,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer @@ -1762,19 +1762,19 @@ spec: name: Name priority: 1 type: string - - JSONPath: .summary.Pass + - JSONPath: .summary.pass name: Pass type: integer - - JSONPath: .summary.Fail + - JSONPath: .summary.fail name: Fail type: integer - - JSONPath: .summary.Warn + - JSONPath: .summary.warn name: Warn type: integer - - JSONPath: .summary.Error + - JSONPath: .summary.error name: Error type: integer - - JSONPath: .summary.Skip + - JSONPath: .summary.skip name: Skip type: integer - JSONPath: .metadata.creationTimestamp @@ -1954,11 +1954,11 @@ spec: status: description: Status indicates the result of the policy rule check enum: - - Pass - - Fail - - Warn - - Error - - Skip + - pass + - fail + - warn + - error + - skip type: string required: - policy @@ -2044,23 +2044,23 @@ spec: summary: description: PolicyReportSummary provides a summary of results properties: - Error: + error: description: Error provides the count of policies that could not be evaluated type: integer - Fail: + fail: description: Fail provides the count of policies whose requirements were not met type: integer - Pass: + pass: description: Pass provides the count of policies whose requirements were met type: integer - Skip: + skip: description: Skip indicates the count of policies that were not selected for evaluation type: integer - Warn: + warn: description: Warn provides the count of unscored policies whose requirements were not met type: integer diff --git a/pkg/api/policyreport/v1alpha1/clusterpolicyreport_types.go b/pkg/api/policyreport/v1alpha1/clusterpolicyreport_types.go index f2caa6e4bf..d4633568af 100755 --- a/pkg/api/policyreport/v1alpha1/clusterpolicyreport_types.go +++ b/pkg/api/policyreport/v1alpha1/clusterpolicyreport_types.go @@ -30,11 +30,11 @@ import ( // +kubebuilder:object:root=true // +kubebuilder:printcolumn:name="Kind",type=string,JSONPath=`.scope.kind`,priority=1 // +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.scope.name`,priority=1 -// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.Pass` -// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.Fail` -// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.Warn` -// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.Error` -// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.Skip` +// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.pass` +// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.fail` +// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.warn` +// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.error` +// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.skip` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:resource:shortName=cpolr diff --git a/pkg/api/policyreport/v1alpha1/clusterreportchangerequest_types.go b/pkg/api/policyreport/v1alpha1/clusterreportchangerequest_types.go index 4d6434e81a..b32bf37649 100644 --- a/pkg/api/policyreport/v1alpha1/clusterreportchangerequest_types.go +++ b/pkg/api/policyreport/v1alpha1/clusterreportchangerequest_types.go @@ -30,11 +30,11 @@ import ( // +kubebuilder:object:root=true // +kubebuilder:printcolumn:name="Kind",type=string,JSONPath=`.scope.kind`,priority=1 // +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.scope.name`,priority=1 -// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.Pass` -// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.Fail` -// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.Warn` -// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.Error` -// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.Skip` +// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.pass` +// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.fail` +// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.warn` +// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.error` +// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.skip` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // ClusterReportChangeRequest is the Schema for the ClusterReportChangeRequests API diff --git a/pkg/api/policyreport/v1alpha1/policyreport_types.go b/pkg/api/policyreport/v1alpha1/policyreport_types.go index fbb52e3272..d6ec05a82c 100755 --- a/pkg/api/policyreport/v1alpha1/policyreport_types.go +++ b/pkg/api/policyreport/v1alpha1/policyreport_types.go @@ -22,11 +22,11 @@ import ( // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. const ( - StatusPass = "Pass" - StatusFail = "Fail" - StatusWarn = "Warn" - StatusError = "Error" - StatusSkip = "Skip" + StatusPass = "pass" + StatusFail = "fail" + StatusWarn = "warn" + StatusError = "error" + StatusSkip = "skip" ) // PolicyReportSummary provides a status count summary @@ -34,33 +34,33 @@ type PolicyReportSummary struct { // Pass provides the count of policies whose requirements were met // +optional - Pass int `json:"Pass"` + Pass int `json:"pass"` // Fail provides the count of policies whose requirements were not met // +optional - Fail int `json:"Fail"` + Fail int `json:"fail"` // Warn provides the count of unscored policies whose requirements were not met // +optional - Warn int `json:"Warn"` + Warn int `json:"warn"` // Error provides the count of policies that could not be evaluated // +optional - Error int `json:"Error"` + Error int `json:"error"` // Skip indicates the count of policies that were not selected for evaluation // +optional - Skip int `json:"Skip"` + Skip int `json:"skip"` } // PolicyStatus has one of the following values: -// - Pass: indicates that the policy requirements are met -// - Fail: indicates that the policy requirements are not met -// - Warn: indicates that the policy requirements and not met, and the policy is not scored -// - Error: indicates that the policy could not be evaluated -// - Skip: indicates that the policy was not selected based on user inputs or applicability +// - pass: indicates that the policy requirements are met +// - fail: indicates that the policy requirements are not met +// - warn: indicates that the policy requirements and not met, and the policy is not scored +// - error: indicates that the policy could not be evaluated +// - skip: indicates that the policy was not selected based on user inputs or applicability // -// +kubebuilder:validation:Enum=Pass;Fail;Warn;Error;Skip +// +kubebuilder:validation:Enum=pass;fail;warn;error;skip type PolicyStatus string // PolicySeverity has one of the following values: @@ -117,11 +117,11 @@ type PolicyReportResult struct { // +kubebuilder:object:root=true // +kubebuilder:printcolumn:name="Kind",type=string,JSONPath=`.scope.kind`,priority=1 // +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.scope.name`,priority=1 -// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.Pass` -// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.Fail` -// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.Warn` -// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.Error` -// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.Skip` +// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.pass` +// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.fail` +// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.warn` +// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.error` +// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.skip` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:resource:shortName=polr diff --git a/pkg/api/policyreport/v1alpha1/reportchangerequest_types.go b/pkg/api/policyreport/v1alpha1/reportchangerequest_types.go index 208b53ccf0..7ba8a2d5fe 100644 --- a/pkg/api/policyreport/v1alpha1/reportchangerequest_types.go +++ b/pkg/api/policyreport/v1alpha1/reportchangerequest_types.go @@ -29,11 +29,11 @@ import ( // +kubebuilder:object:root=true // +kubebuilder:printcolumn:name="Kind",type=string,JSONPath=`.scope.kind`,priority=1 // +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.scope.name`,priority=1 -// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.Pass` -// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.Fail` -// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.Warn` -// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.Error` -// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.Skip` +// +kubebuilder:printcolumn:name="Pass",type=integer,JSONPath=`.summary.pass` +// +kubebuilder:printcolumn:name="Fail",type=integer,JSONPath=`.summary.fail` +// +kubebuilder:printcolumn:name="Warn",type=integer,JSONPath=`.summary.warn` +// +kubebuilder:printcolumn:name="Error",type=integer,JSONPath=`.summary.error` +// +kubebuilder:printcolumn:name="Skip",type=integer,JSONPath=`.summary.skip` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // ReportChangeRequest is the Schema for the ReportChangeRequests API diff --git a/pkg/kyverno/apply/generate.go b/pkg/kyverno/apply/generate.go index 6a3239ed54..85e5a49ec9 100644 --- a/pkg/kyverno/apply/generate.go +++ b/pkg/kyverno/apply/generate.go @@ -134,25 +134,25 @@ func updateSummary(results []interface{}) map[string]interface{} { continue } - pass, _ := summary["Pass"].(int64) + pass, _ := summary[report.StatusPass].(int64) pass += int64(len(resources)) - summary["Pass"] = pass + summary[report.StatusPass] = pass case report.StatusFail: - fail, _ := summary["Fail"].(int64) + fail, _ := summary[report.StatusFail].(int64) fail++ - summary["Fail"] = fail - case "Warn": - warn, _ := summary["Warn"].(int64) + summary[report.StatusFail] = fail + case report.StatusWarn: + warn, _ := summary[report.StatusWarn].(int64) warn++ - summary["warn"] = warn - case "Error": - e, _ := summary["Error"].(int64) + summary[report.StatusWarn] = warn + case report.StatusError: + e, _ := summary[report.StatusError].(int64) e++ - summary["Error"] = e - case "Skip": - skip, _ := summary["Skip"].(int64) + summary[report.StatusError] = e + case report.StatusSkip: + skip, _ := summary[report.StatusSkip].(int64) skip++ - summary["Skip"] = skip + summary[report.StatusSkip] = skip } } diff --git a/pkg/kyverno/apply/generate_test.go b/pkg/kyverno/apply/generate_test.go index 0551b6f9a1..ec5650dca5 100644 --- a/pkg/kyverno/apply/generate_test.go +++ b/pkg/kyverno/apply/generate_test.go @@ -4,6 +4,7 @@ import ( "reflect" "testing" + report "github.com/kyverno/kyverno/pkg/api/policyreport/v1alpha1" "gotest.tools/assert" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -21,7 +22,7 @@ func Test_mergeClusterReport(t *testing.T) { "results": []interface{}{ map[string]interface{}{ "policy": "ns-polr-1", - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 10), }, }, @@ -37,7 +38,7 @@ func Test_mergeClusterReport(t *testing.T) { "results": []interface{}{ map[string]interface{}{ "policy": "ns-polr-2", - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 5), }, }, @@ -51,7 +52,7 @@ func Test_mergeClusterReport(t *testing.T) { "results": []interface{}{ map[string]interface{}{ "policy": "polr-3", - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 1), }, }, @@ -67,7 +68,7 @@ func Test_mergeClusterReport(t *testing.T) { "results": []interface{}{ map[string]interface{}{ "policy": "cpolr-4", - "status": "Fail", + "status": report.StatusFail, }, }, }, @@ -82,7 +83,7 @@ func Test_mergeClusterReport(t *testing.T) { "results": []interface{}{ map[string]interface{}{ "policy": "cpolr-5", - "status": "Fail", + "status": report.StatusFail, }, }, }, @@ -92,21 +93,21 @@ func Test_mergeClusterReport(t *testing.T) { expectedResults := []interface{}{ map[string]interface{}{ "policy": "ns-polr-2", - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 5), }, map[string]interface{}{ "policy": "polr-3", - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 1), }, map[string]interface{}{ "policy": "cpolr-4", - "status": "Fail", + "status": report.StatusFail, }, map[string]interface{}{ "policy": "cpolr-5", - "status": "Fail", + "status": report.StatusFail, }, } @@ -123,28 +124,28 @@ func Test_mergeClusterReport(t *testing.T) { summary, _, err := unstructured.NestedMap(cpolr.UnstructuredContent(), "summary") assert.NilError(t, err) - assert.Assert(t, summary["Pass"].(int64) == 6, summary["Pass"]) - assert.Assert(t, summary["Fail"].(int64) == 2, summary["Fail"]) + assert.Assert(t, summary[report.StatusPass].(int64) == 6, summary[report.StatusPass]) + assert.Assert(t, summary[report.StatusFail].(int64) == 2, summary[report.StatusFail]) } func Test_updateSummary(t *testing.T) { results := []interface{}{ map[string]interface{}{ - "status": "Pass", + "status": report.StatusPass, "resources": make([]interface{}, 5), }, map[string]interface{}{ - "status": "Fail", + "status": report.StatusFail, }, map[string]interface{}{ - "status": "Fail", + "status": report.StatusFail, }, map[string]interface{}{ - "status": "Fail", + "status": report.StatusFail, }, } summary := updateSummary(results) - assert.Assert(t, summary["Pass"].(int64) == 5, summary["Pass"]) - assert.Assert(t, summary["Fail"].(int64) == 3, summary["Fail"]) + assert.Assert(t, summary[report.StatusPass].(int64) == 5, summary[report.StatusPass]) + assert.Assert(t, summary[report.StatusFail].(int64) == 3, summary[report.StatusFail]) } diff --git a/pkg/kyverno/apply/report_test.go b/pkg/kyverno/apply/report_test.go index 955369ed08..82ddea4e61 100644 --- a/pkg/kyverno/apply/report_test.go +++ b/pkg/kyverno/apply/report_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + preport "github.com/kyverno/kyverno/pkg/api/policyreport/v1alpha1" report "github.com/kyverno/kyverno/pkg/api/policyreport/v1alpha1" "github.com/kyverno/kyverno/pkg/common" "github.com/kyverno/kyverno/pkg/engine/response" @@ -75,15 +76,15 @@ func Test_buildPolicyReports(t *testing.T) { assert.Assert(t, report.GetKind() == "ClusterPolicyReport") assert.Assert(t, len(report.UnstructuredContent()["results"].([]interface{})) == 2) assert.Assert(t, - report.UnstructuredContent()["summary"].(map[string]interface{})["Pass"].(int64) == 1, - report.UnstructuredContent()["summary"].(map[string]interface{})["Pass"].(int64)) + report.UnstructuredContent()["summary"].(map[string]interface{})[preport.StatusPass].(int64) == 1, + report.UnstructuredContent()["summary"].(map[string]interface{})[preport.StatusPass].(int64)) } else { assert.Assert(t, report.GetName() == "policyreport-ns-policy1-namespace") assert.Assert(t, report.GetKind() == "PolicyReport") assert.Assert(t, len(report.UnstructuredContent()["results"].([]interface{})) == 2) assert.Assert(t, - report.UnstructuredContent()["summary"].(map[string]interface{})["Pass"].(int64) == 1, - report.UnstructuredContent()["summary"].(map[string]interface{})["Pass"].(int64)) + report.UnstructuredContent()["summary"].(map[string]interface{})[preport.StatusPass].(int64) == 1, + report.UnstructuredContent()["summary"].(map[string]interface{})[preport.StatusPass].(int64)) } } } @@ -100,156 +101,29 @@ func Test_buildPolicyResults(t *testing.T) { for _, r := range result { switch r.Rule { case "policy1-rule1", "clusterpolicy2-rule1": - assert.Assert(t, r.Status == report.PolicyStatus("Pass")) + assert.Assert(t, r.Status == report.PolicyStatus(preport.StatusPass)) case "policy1-rule2", "clusterpolicy2-rule2": - assert.Assert(t, r.Status == report.PolicyStatus("Fail")) + assert.Assert(t, r.Status == report.PolicyStatus(preport.StatusFail)) } } } } -func Test_mergeSucceededResults(t *testing.T) { - resultsMap := map[string][]*report.PolicyReportResult{ - clusterpolicyreport: { - { - Status: report.PolicyStatus("Pass"), - Policy: "clusterpolicy", - Rule: "clusterrule", - Resources: []*v1.ObjectReference{ - { - Name: "cluster-resource-1", - }, - { - Name: "cluster-resource-2", - }, - }, - }, - { - Status: report.PolicyStatus("Pass"), - Policy: "clusterpolicy", - Rule: "clusterrule", - Resources: []*v1.ObjectReference{ - { - Name: "cluster-resource-3", - }, - { - Name: "cluster-resource-4", - }, - }, - }, - { - Status: report.PolicyStatus("Fail"), - Policy: "clusterpolicy", - Rule: "clusterrule", - Resources: []*v1.ObjectReference{ - { - Name: "cluster-resource-5", - }, - }, - }, - }, - - "policyreport-ns-test1": { - { - Status: report.PolicyStatus("Pass"), - Policy: "test1-policy", - Rule: "test1-rule", - Resources: []*v1.ObjectReference{ - { - Name: "resource-1", - }, - { - Name: "resource-2", - }, - }, - }, - { - Status: report.PolicyStatus("Pass"), - Policy: "test1-policy", - Rule: "test1-rule", - Resources: []*v1.ObjectReference{ - { - Name: "resource-3", - }, - { - Name: "resource-4", - }, - }, - }, - { - Status: report.PolicyStatus("Fail"), - Policy: "test1-policy", - Rule: "test1-rule", - Resources: []*v1.ObjectReference{ - { - Name: "resource-5", - }, - }, - }, - }, - "policyreport-ns-test2": { - { - Status: report.PolicyStatus("Pass"), - Policy: "test2-policy", - Rule: "test2-rule", - Resources: []*v1.ObjectReference{ - { - Name: "resource-1", - }, - { - Name: "resource-2", - }, - }, - }, - }, - } - - results := mergeSucceededResults(resultsMap) - assert.Assert(t, len(results) == len(resultsMap), len(results), len(resultsMap)) - for key, result := range results { - if key == clusterpolicyreport { - assert.Assert(t, len(result) == 3, len(result)) - for _, res := range result { - if res.Status == report.PolicyStatus("Pass") { - assert.Assert(t, len(res.Resources) == 2, len(res.Resources)) - } else { - assert.Assert(t, len(res.Resources) == 1, len(res.Resources)) - } - } - } - - if key == "policyreport-ns-test1" { - assert.Assert(t, len(result) == 3, len(result)) - for _, res := range result { - if res.Status == report.PolicyStatus("Pass") { - assert.Assert(t, len(res.Resources) == 2, len(res.Resources)) - } else { - assert.Assert(t, len(res.Resources) == 1, len(res.Resources)) - } - } - } - - if key == "policyreport-ns-test2" { - assert.Assert(t, len(result[0].Resources) == 2, len(result[0].Resources)) - } - } -} - func Test_calculateSummary(t *testing.T) { results := []*report.PolicyReportResult{ { Resources: make([]*v1.ObjectReference, 5), - Status: report.PolicyStatus("Pass"), + Status: report.PolicyStatus(preport.StatusPass), }, - {Status: report.PolicyStatus("Fail")}, - {Status: report.PolicyStatus("Fail")}, - {Status: report.PolicyStatus("Fail")}, + {Status: report.PolicyStatus(preport.StatusFail)}, + {Status: report.PolicyStatus(preport.StatusFail)}, + {Status: report.PolicyStatus(preport.StatusFail)}, { Resources: make([]*v1.ObjectReference, 1), - Status: report.PolicyStatus("Pass")}, + Status: report.PolicyStatus(preport.StatusPass)}, { Resources: make([]*v1.ObjectReference, 4), - Status: report.PolicyStatus("Pass"), + Status: report.PolicyStatus(preport.StatusPass), }, } diff --git a/pkg/policyreport/builder.go b/pkg/policyreport/builder.go index 0f69453726..e18ce7baa0 100755 --- a/pkg/policyreport/builder.go +++ b/pkg/policyreport/builder.go @@ -88,6 +88,7 @@ func (pvb *requestBuilder) build(info Info) (req *unstructured.Unstructured, err result.Rule = rule.Name result.Message = rule.Message result.Status = report.PolicyStatus(rule.Check) + fmt.Println("======status", result.Status) results = append(results, result) }