Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attach namespaces to non-namespaced resources #320

Merged
merged 6 commits into from
Jul 16, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion pkg/process/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,50 @@ const (
AnnotationNamespaced = MetadataPrefix + "/namespaced"
)

// This is a list of "cluster-wide" resources harvested from `kubectl api-resources --namespaced=false`
// This helps us to know which objects we should NOT apply namespaces to automatically.
// We can add to this list periodically if new types are added. There is no reason not to add popular CRD types here as well.
// Alternatively, library authors can add annotations to control namespacing for a type as well.
var clusterWideKinds = []string{
sh0rez marked this conversation as resolved.
Show resolved Hide resolved
"APIService",
"CertificateSigningRequest",
"ClusterRole",
"ClusterRoleBinding",
"ComponentStatus",
"CSIDriver",
"CSINode",
"CustomResourceDefinition",
"MutatingWebhookConfiguration",
"Namespace",
"Node",
"NodeMetrics",
"PersistentVolume",
"PodSecurityPolicy",
"PriorityClass",
"RuntimeClass",
"SelfSubjectAccessReview",
"SelfSubjectRulesReview",
"StorageClass",
"SubjectAccessReview",
"TokenReview",
"ValidatingWebhookConfiguration",
"VolumeAttachment",

// cert-manager
"ClusterIssuer",
sh0rez marked this conversation as resolved.
Show resolved Hide resolved
}

// clusterWideMap is a generated lookup table on top of clusterWideKinds
var clusterWideMap = buildClusterWideMap()

func buildClusterWideMap() map[string]bool {
m := make(map[string]bool, len(clusterWideKinds))
for _, k := range clusterWideKinds {
m[k] = true
}
return m
}

// Namespace injects the default namespace of the environment into each
// resources, that does not already define one. AnnotationNamespaced can be used
// to disable this per resource
Expand All @@ -20,7 +64,9 @@ func Namespace(list manifest.List, def string) manifest.List {

for i, m := range list {
namespaced := true

if clusterWideMap[m.Kind()] {
namespaced = false
}
// check for annotation override
if s, ok := m.Metadata().Annotations()[AnnotationNamespaced]; ok {
namespaced = s == "true"
Expand Down