2024-04-17 09:46:18 +02:00
|
|
|
package validation
|
|
|
|
|
|
|
|
import (
|
|
|
|
admissionutils "github.com/kyverno/kyverno/pkg/utils/admission"
|
|
|
|
reportutils "github.com/kyverno/kyverno/pkg/utils/report"
|
|
|
|
"github.com/kyverno/kyverno/pkg/webhooks/handlers"
|
|
|
|
admissionv1 "k8s.io/api/admission/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
)
|
|
|
|
|
2024-10-11 15:12:29 +05:30
|
|
|
func needsReports(request handlers.AdmissionRequest, resource unstructured.Unstructured, admissionReport bool, reportConfig reportutils.ReportingConfiguration) bool {
|
2024-04-17 09:46:18 +02:00
|
|
|
createReport := admissionReport
|
|
|
|
if admissionutils.IsDryRun(request.AdmissionRequest) {
|
|
|
|
createReport = false
|
|
|
|
}
|
2024-10-11 15:12:29 +05:30
|
|
|
if !reportConfig.ValidateReportsEnabled() {
|
|
|
|
createReport = false
|
|
|
|
}
|
2024-04-17 09:46:18 +02:00
|
|
|
// we don't need reports for deletions
|
|
|
|
if request.Operation == admissionv1.Delete {
|
|
|
|
createReport = false
|
|
|
|
}
|
|
|
|
// check if the resource supports reporting
|
|
|
|
if !reportutils.IsGvkSupported(schema.GroupVersionKind(request.Kind)) {
|
|
|
|
createReport = false
|
|
|
|
}
|
|
|
|
// if the underlying resource has no UID don't create a report
|
|
|
|
if resource.GetUID() == "" {
|
|
|
|
createReport = false
|
|
|
|
}
|
|
|
|
return createReport
|
|
|
|
}
|