mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
refactor Gkv.isNamespaceableKind
This commit is contained in:
@@ -5,6 +5,8 @@ package resid
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Gvk identifies a Kubernetes API type.
|
// Gvk identifies a Kubernetes API type.
|
||||||
@@ -172,39 +174,22 @@ func (x Gvk) IsSelected(selector *Gvk) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var notNamespaceableKinds = []string{
|
// toKyamlTypeMeta returns a yaml.TypeMeta from x's information.
|
||||||
"APIService",
|
func (x Gvk) toKyamlTypeMeta() yaml.TypeMeta {
|
||||||
"CSIDriver",
|
var apiVersion strings.Builder
|
||||||
"CSINode",
|
if x.Group != "" {
|
||||||
"CertificateSigningRequest",
|
apiVersion.WriteString(x.Group)
|
||||||
"Cluster",
|
apiVersion.WriteString("/")
|
||||||
"ClusterRole",
|
}
|
||||||
"ClusterRoleBinding",
|
apiVersion.WriteString(x.Version)
|
||||||
"ComponentStatus",
|
return yaml.TypeMeta{
|
||||||
"CustomResourceDefinition",
|
APIVersion: apiVersion.String(),
|
||||||
"MutatingWebhookConfiguration",
|
Kind: x.Kind,
|
||||||
"Namespace",
|
}
|
||||||
"Node",
|
|
||||||
"PersistentVolume",
|
|
||||||
"PodSecurityPolicy",
|
|
||||||
"PriorityClass",
|
|
||||||
"RuntimeClass",
|
|
||||||
"SelfSubjectAccessReview",
|
|
||||||
"SelfSubjectRulesReview",
|
|
||||||
"StorageClass",
|
|
||||||
"SubjectAccessReview",
|
|
||||||
"TokenReview",
|
|
||||||
"ValidatingWebhookConfiguration",
|
|
||||||
"VolumeAttachment",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNamespaceableKind returns true if x is a namespaceable Gvk
|
// 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
|
// Implements https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#not-all-objects-are-in-a-namespace
|
||||||
func (x Gvk) IsNamespaceableKind() bool {
|
func (x Gvk) IsNamespaceableKind() bool {
|
||||||
for _, k := range notNamespaceableKinds {
|
return x.toKyamlTypeMeta().IsNamespaceable()
|
||||||
if k == x.Kind {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user