coredns/plugin/kubernetes/namespace.go
Mat Lowery 9d5b8cd13d
kubernetes: Improve namespace usage (#4767)
* Use GetByKey instead of List in GetNamespaceByName.
* Add ToNamespace to reduce memory for namespace cache.

Signed-off-by: Mat Lowery <mlowery@ebay.com>
2021-07-29 23:27:25 -04:00

27 lines
862 B
Go

package kubernetes
// filteredNamespaceExists checks if namespace exists in this cluster
// according to any `namespace_labels` plugin configuration specified.
// Returns true even for namespaces not exposed by plugin configuration,
// see namespaceExposed.
func (k *Kubernetes) filteredNamespaceExists(namespace string) bool {
_, err := k.APIConn.GetNamespaceByName(namespace)
if err != nil {
return false
}
return true
}
// configuredNamespace returns true when the namespace is exposed through the plugin
// `namespaces` configuration.
func (k *Kubernetes) configuredNamespace(namespace string) bool {
_, ok := k.Namespaces[namespace]
if len(k.Namespaces) > 0 && !ok {
return false
}
return true
}
func (k *Kubernetes) namespaceExposed(namespace string) bool {
return k.configuredNamespace(namespace) && k.filteredNamespaceExists(namespace)
}