From 4b8b8cbfa6ef815fa0dfa8f805378f1200ebac4d Mon Sep 17 00:00:00 2001 From: Shuting Zhao Date: Mon, 5 Apr 2021 13:05:47 -0700 Subject: [PATCH] remove namespace field on kind Namespace Signed-off-by: Shuting Zhao --- pkg/generate/resource.go | 3 +++ pkg/utils/util.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/generate/resource.go b/pkg/generate/resource.go index 63d068d98e..0972bd8d56 100644 --- a/pkg/generate/resource.go +++ b/pkg/generate/resource.go @@ -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 diff --git a/pkg/utils/util.go b/pkg/utils/util.go index 3a25c3e950..62b8ccce31 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -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