From c59b393fa465b487cb48685e6bb7b00ff4a7be8c Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Thu, 1 Oct 2020 11:28:58 -0700 Subject: [PATCH] refactor Gkv.isNamespaceableKind --- api/resid/gvk.go | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/api/resid/gvk.go b/api/resid/gvk.go index f3f94999e..4d18713a2 100644 --- a/api/resid/gvk.go +++ b/api/resid/gvk.go @@ -5,6 +5,8 @@ package resid import ( "strings" + + "sigs.k8s.io/kustomize/kyaml/yaml" ) // Gvk identifies a Kubernetes API type. @@ -172,39 +174,22 @@ func (x Gvk) IsSelected(selector *Gvk) bool { return true } -var notNamespaceableKinds = []string{ - "APIService", - "CSIDriver", - "CSINode", - "CertificateSigningRequest", - "Cluster", - "ClusterRole", - "ClusterRoleBinding", - "ComponentStatus", - "CustomResourceDefinition", - "MutatingWebhookConfiguration", - "Namespace", - "Node", - "PersistentVolume", - "PodSecurityPolicy", - "PriorityClass", - "RuntimeClass", - "SelfSubjectAccessReview", - "SelfSubjectRulesReview", - "StorageClass", - "SubjectAccessReview", - "TokenReview", - "ValidatingWebhookConfiguration", - "VolumeAttachment", +// toKyamlTypeMeta returns a yaml.TypeMeta from x's information. +func (x Gvk) toKyamlTypeMeta() yaml.TypeMeta { + var apiVersion strings.Builder + if x.Group != "" { + apiVersion.WriteString(x.Group) + apiVersion.WriteString("/") + } + apiVersion.WriteString(x.Version) + return yaml.TypeMeta{ + APIVersion: apiVersion.String(), + Kind: x.Kind, + } } // IsNamespaceableKind returns true if x is a namespaceable Gvk // Implements https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#not-all-objects-are-in-a-namespace func (x Gvk) IsNamespaceableKind() bool { - for _, k := range notNamespaceableKinds { - if k == x.Kind { - return false - } - } - return true + return x.toKyamlTypeMeta().IsNamespaceable() }