Skip to content

Commit

Permalink
Merge pull request #3054 from Shell32-Natsu/isnamespaceable
Browse files Browse the repository at this point in the history
refactor Gkv.isNamespaceableKind
  • Loading branch information
monopole authored Oct 2, 2020
2 parents 2fb8603 + c59b393 commit 3ffc13d
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions api/resid/gvk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package resid

import (
"strings"

"sigs.k8s.io/kustomize/kyaml/yaml"
)

// Gvk identifies a Kubernetes API type.
Expand Down Expand Up @@ -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()
}

0 comments on commit 3ffc13d

Please sign in to comment.