1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

remove namespace field on kind Namespace

Signed-off-by: Shuting Zhao <shutting06@gmail.com>
This commit is contained in:
Shuting Zhao 2021-04-05 13:05:47 -07:00
parent 3ab75095b7
commit 4b8b8cbfa6
2 changed files with 9 additions and 0 deletions

View file

@ -7,6 +7,9 @@ import (
)
func getResource(client *dclient.Client, resourceSpec kyverno.ResourceSpec) (*unstructured.Unstructured, error) {
if resourceSpec.Kind == "Namespace" {
resourceSpec.Namespace = ""
}
resource, err := client.GetResource(resourceSpec.APIVersion, resourceSpec.Kind, resourceSpec.Namespace, resourceSpec.Name)
if err != nil {
return nil, err

View file

@ -104,6 +104,9 @@ func ExtractResources(newRaw []byte, request *v1beta1.AdmissionRequest) (unstruc
if err != nil {
return emptyResource, emptyResource, fmt.Errorf("failed to convert new raw to unstructured: %v", err)
}
if newResource.GetKind() == "Namespace" {
newResource.SetNamespace("")
}
}
// Old Resource
@ -113,6 +116,9 @@ func ExtractResources(newRaw []byte, request *v1beta1.AdmissionRequest) (unstruc
if err != nil {
return emptyResource, emptyResource, fmt.Errorf("failed to convert old raw to unstructured: %v", err)
}
if oldResource.GetKind() == "Namespace" {
oldResource.SetNamespace("")
}
}
return newResource, oldResource, err