Add namespace_labels
configuration for kubernetes plugin (#2707)
This commit is contained in:
parent
43c3e0ab68
commit
a3dd8cdf8d
9 changed files with 278 additions and 40 deletions
|
@ -1,20 +1,27 @@
|
|||
package kubernetes
|
||||
|
||||
// namespace checks if namespace n exists in this cluster. This returns true
|
||||
// even for non exposed namespaces, see namespaceExposed.
|
||||
func (k *Kubernetes) namespace(n string) bool {
|
||||
ns, err := k.APIConn.GetNamespaceByName(n)
|
||||
// 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 {
|
||||
ns, err := k.APIConn.GetNamespaceByName(namespace)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ns.ObjectMeta.Name == n
|
||||
return ns.ObjectMeta.Name == namespace
|
||||
}
|
||||
|
||||
// namespaceExposed returns true when the namespace is exposed.
|
||||
func (k *Kubernetes) namespaceExposed(namespace string) bool {
|
||||
// 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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue