coredns/plugin/kubernetes/namespace.go
xuweiwei 5f900b86f5
cleanup some code (#4989)
Automatically submitted.
2021-11-19 16:15:58 +00:00

24 lines
833 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)
return err == nil
}
// 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)
}