1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-08 10:04:25 +00:00

fix: GVK fallback in policy context ()

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-03-22 13:07:12 +01:00 committed by GitHub
parent b0243e1215
commit 3aa3c022f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,9 +71,13 @@ func (c *PolicyContext) RequestResource() metav1.GroupVersionResource {
}
func (c *PolicyContext) ResourceKind() (schema.GroupVersionKind, string) {
// TODO: fallback
// if the top level GVK is empty, fallback to the GVK of the resource
if c.gvk.Empty() {
return c.newResource.GroupVersionKind(), ""
if c.newResource.Object != nil {
return c.newResource.GroupVersionKind(), ""
} else {
return c.oldResource.GroupVersionKind(), ""
}
}
return c.gvk, c.subresource
}