mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Consolidate IsClusterKind and IsNamespaceableKind method to avoid duplication
This commit is contained in:
@@ -160,27 +160,6 @@ func (x Gvk) IsSelected(selector *Gvk) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var clusterLevelKinds = []string{
|
||||
"APIService",
|
||||
"ClusterRoleBinding",
|
||||
"ClusterRole",
|
||||
"CustomResourceDefinition",
|
||||
"Namespace",
|
||||
"PersistentVolume",
|
||||
"MutatingWebhookConfiguration",
|
||||
"ValidatingWebhookConfiguration",
|
||||
}
|
||||
|
||||
// IsClusterKind returns true if x is a cluster-level Gvk
|
||||
func (x Gvk) IsClusterKind() bool {
|
||||
for _, k := range clusterLevelKinds {
|
||||
if k == x.Kind {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var notNamespaceableKinds = []string{
|
||||
"APIService",
|
||||
"CSIDriver",
|
||||
@@ -207,7 +186,7 @@ var notNamespaceableKinds = []string{
|
||||
"VolumeAttachment",
|
||||
}
|
||||
|
||||
// IsNamespaceableKind returns true if x is a namespable Gvk
|
||||
// IsNamespaceableKind returns true if x is a namespeable 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 {
|
||||
|
||||
@@ -488,12 +488,12 @@ func (m *resWrangler) makeCopy(copier resCopier) ResMap {
|
||||
func (m *resWrangler) SubsetThatCouldBeReferencedByResource(
|
||||
inputRes *resource.Resource) ResMap {
|
||||
inputId := inputRes.OrgId()
|
||||
if inputId.IsClusterKind() {
|
||||
if !inputId.IsNamespaceableKind() {
|
||||
return m
|
||||
}
|
||||
result := New()
|
||||
for _, r := range m.Resources() {
|
||||
if r.OrgId().IsClusterKind() || inputRes.InSameFuzzyNamespace(r) {
|
||||
if !r.OrgId().IsNamespaceableKind() || inputRes.InSameFuzzyNamespace(r) {
|
||||
err := result.Append(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -62,7 +62,7 @@ const metaNamespace = "metadata/namespace"
|
||||
// object itself doesn't live in a namespace).
|
||||
func doIt(id resid.ResId, fs *config.FieldSpec) bool {
|
||||
return fs.Path != metaNamespace ||
|
||||
(fs.Path == metaNamespace && !id.IsClusterKind())
|
||||
(fs.Path == metaNamespace && id.IsNamespaceableKind())
|
||||
}
|
||||
|
||||
func (p *NamespaceTransformerPlugin) changeNamespace(
|
||||
|
||||
@@ -63,7 +63,7 @@ const metaNamespace = "metadata/namespace"
|
||||
// object itself doesn't live in a namespace).
|
||||
func doIt(id resid.ResId, fs *config.FieldSpec) bool {
|
||||
return fs.Path != metaNamespace ||
|
||||
(fs.Path == metaNamespace && !id.IsClusterKind())
|
||||
(fs.Path == metaNamespace && id.IsNamespaceableKind())
|
||||
}
|
||||
|
||||
func (p *plugin) changeNamespace(
|
||||
|
||||
Reference in New Issue
Block a user