1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/pkg/webhooks/utils/exclude_test.go
Charles-Edouard Brétéché e0ab72bb9a
feat: reports v2 implementation (#4608)
This PR refactors the reports generation code.
It removes RCR and CRCR crds and replaces them with AdmissionReport, ClusterAdmissionReport, BackgroundScanReport and ClusterBackgroundScanReport crds.

The new reports system is based on 4 controllers:

Admission reports controller is responsible for cleaning up admission reports and attaching admission reports to their corresponding resource in case of a creation
Background scan reports controller is responsible for creating background scan reports when a resource and/or policy changes
Aggregation controller takes care of aggregation per resource reports into higher level reports (per namespace)
Resources controller is responsible for watching reports that need background scan reports
I added two new flags to disable admission reports and/or background scan reports, the whole reporting system can be disabled if something goes wrong.

I also added a flag to split reports in chunks to avoid creating too large resources.

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com>
Co-authored-by: prateekpandey14 <prateek.pandey@nirmata.com>
2022-09-28 17:15:16 +05:30

76 lines
1.3 KiB
Go

package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExcludeKyvernoResources(t *testing.T) {
type args struct {
kind string
}
tests := []struct {
name string
args args
want bool
}{{
name: "Policy",
args: args{"Policy"},
want: false,
}, {
name: "ClusterPolicy",
args: args{"ClusterPolicy"},
want: false,
}, {
name: "ClusterPolicyReport",
args: args{"ClusterPolicyReport"},
want: true,
}, {
name: "PolicyReport",
args: args{"PolicyReport"},
want: true,
}, {
name: "AdmissionReport",
args: args{"AdmissionReport"},
want: true,
}, {
name: "BackgroundScanReport",
args: args{"BackgroundScanReport"},
want: true,
}, {
name: "GenerateRequest",
args: args{"GenerateRequest"},
want: true,
}, {
name: "ClusterAdmissionReport",
args: args{"ClusterAdmissionReport"},
want: true,
}, {
name: "ClusterBackgroundScanReport",
args: args{"ClusterBackgroundScanReport"},
want: true,
}, {
name: "Pod",
args: args{"Pod"},
want: false,
}, {
name: "Job",
args: args{"Job"},
want: false,
}, {
name: "Deployment",
args: args{"Deployment"},
want: false,
}, {
name: "empty",
args: args{""},
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ExcludeKyvernoResources(tt.args.kind)
assert.Equal(t, tt.want, got)
})
}
}