Merge pull request #195 from zalando-incubator/databases-rest-endpoint

Add a REST endpoint to list databases in all clusters
This commit is contained in:
zerg-junior
2018-01-09 11:53:32 +01:00
committed by GitHub
5 changed files with 70 additions and 4 deletions
+24
View File
@@ -2,6 +2,7 @@ package controller
import (
"fmt"
"sort"
"sync/atomic"
"github.com/Sirupsen/logrus"
@@ -32,6 +33,29 @@ func (c *Controller) ClusterStatus(team, cluster string) (*spec.ClusterStatus, e
return status, nil
}
// ClusterDatabasesMap returns for each cluster the list of databases running there
func (c *Controller) ClusterDatabasesMap() map[string][]string {
m := make(map[string][]string)
// avoid modifying the cluster list while we are fetching each one of them.
c.clustersMu.RLock()
defer c.clustersMu.RUnlock()
for _, cluster := range c.clusters {
// GetSpec holds the specMu lock of a cluster
if spec, err := cluster.GetSpec(); err == nil {
for database := range spec.Spec.Databases {
m[cluster.Name] = append(m[cluster.Name], database)
}
sort.Strings(m[cluster.Name])
} else {
c.logger.Warningf("could not get the list of databases for cluster %q: %v", cluster.Name, err)
}
}
return m
}
// TeamClusterList returns team-clusters map
func (c *Controller) TeamClusterList() map[string][]spec.NamespacedName {
return c.teamClusters