mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-01 11:29:56 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user