From fa000aeff5a87eed64a8ef4052b4f3cd61fddaa7 Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Thu, 9 Jan 2025 11:18:22 -0800 Subject: [PATCH] chore: update IsManageableSystemNamespace (#1527) The IsManageableSystemNamespace function currently requires typed namespace objects to have their GroupVersionKind set. This update adds checks for the v1.Namespace type to avoid that requirement. --- pkg/syncer/differ/special_namespaces.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/syncer/differ/special_namespaces.go b/pkg/syncer/differ/special_namespaces.go index 2191b99a70..b0a408dc8c 100644 --- a/pkg/syncer/differ/special_namespaces.go +++ b/pkg/syncer/differ/special_namespaces.go @@ -17,6 +17,7 @@ package differ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "kpt.dev/configsync/pkg/kinds" "kpt.dev/configsync/pkg/policycontroller" "sigs.k8s.io/controller-runtime/pkg/client" @@ -38,7 +39,13 @@ var SpecialNamespaces = map[string]bool{ // IsManageableSystemNamespace returns if the input namespace is a manageable system namespace. func IsManageableSystemNamespace(o client.Object) bool { - if o.GetObjectKind().GroupVersionKind().GroupKind() != kinds.Namespace().GroupKind() { + switch t := o.(type) { + case *corev1.Namespace: + case *unstructured.Unstructured: + if t.GroupVersionKind().GroupKind() != kinds.Namespace().GroupKind() { + return false + } + default: return false } return SpecialNamespaces[o.GetName()]