mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
fix panic when rules are empty (#11821)
Signed-off-by: MUzairS15 <muzair.shaikh810@gmail.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
5573e5cded
commit
d84fc7b4e1
2 changed files with 19 additions and 0 deletions
|
@ -114,6 +114,10 @@ func checkPolicy(spec *kyvernov1.Spec) (bool, string) {
|
|||
|
||||
func checkRuleCount(spec *kyvernov1.Spec) (bool, string) {
|
||||
var msg string
|
||||
if len(spec.Rules) == 0 {
|
||||
msg = "skip generating ValidatingAdmissionPolicy: no rules found."
|
||||
return false, msg
|
||||
}
|
||||
if len(spec.Rules) > 1 {
|
||||
msg = "skip generating ValidatingAdmissionPolicy: multiple rules are not applicable."
|
||||
return false, msg
|
||||
|
|
|
@ -841,6 +841,21 @@ func Test_Can_Generate_ValidatingAdmissionPolicy(t *testing.T) {
|
|||
`),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "policy-with-no-rules",
|
||||
policy: []byte(`
|
||||
{
|
||||
"apiVersion": "kyverno.io/v1",
|
||||
"kind": "ClusterPolicy",
|
||||
"metadata": {
|
||||
"name": "empty-policy"
|
||||
},
|
||||
"spec": {
|
||||
"rules": []
|
||||
}
|
||||
}`),
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
|
Loading…
Add table
Reference in a new issue