Skip to content

Commit

Permalink
return cluster list without team prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mkabilov committed Aug 14, 2017
1 parent 71822a6 commit 646aae0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
26 changes: 24 additions & 2 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type ControllerInformer interface {
GetConfig() *spec.ControllerConfig
GetOperatorConfig() *config.Config
GetStatus() *spec.ControllerStatus
TeamClusterList() map[string][]spec.NamespacedName
ClusterStatus(team, cluster string) (*spec.ClusterStatus, error)
TeamClustersStatus(team string) ([]*spec.ClusterStatus, error)
ClusterLogs(team, cluster string) ([]*spec.LogEntry, error)
WorkerLogs(workerID uint32) ([]*spec.LogEntry, error)
ListQueue(workerID uint32) (*spec.QueueDump, error)
Expand Down Expand Up @@ -142,9 +142,31 @@ func (s *Server) clusters(w http.ResponseWriter, req *http.Request) {
if matches := clusterStatusURL.FindAllStringSubmatch(req.URL.Path, -1); matches != nil {
resp, err = s.controller.ClusterStatus(matches[0][1], matches[0][2])
} else if matches := teamURL.FindAllStringSubmatch(req.URL.Path, -1); matches != nil {
resp, err = s.controller.TeamClustersStatus(matches[0][1])
teamClusters := s.controller.TeamClusterList()
clusters, found := teamClusters[matches[0][1]]
if !found {
s.respond(nil, fmt.Errorf("could not find clusters for the team"), w)
}

clusterNames := make([]string, 0)
for _, cluster := range clusters {
clusterNames = append(clusterNames, cluster.Name[len(matches[0][1])+1:])
}

s.respond(clusterNames, nil, w)
return
} else if matches := clusterLogsURL.FindAllStringSubmatch(req.URL.Path, -1); matches != nil {
resp, err = s.controller.ClusterLogs(matches[0][1], matches[0][2])
} else if req.URL.Path == "/clusters/" {
res := make(map[string][]string)
for team, clusters := range s.controller.TeamClusterList() {
for _, cluster := range clusters {
res[team] = append(res[team], cluster.Name[len(team)+1:])
}
}

s.respond(res, nil, w)
return
} else {
s.respond(nil, fmt.Errorf("page not found"), w)
return
Expand Down
24 changes: 3 additions & 21 deletions pkg/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,9 @@ func (c *Controller) ClusterStatus(team, cluster string) (*spec.ClusterStatus, e
return status, nil
}

// TeamClustersStatus dumps logs of all the team clusters
func (c *Controller) TeamClustersStatus(team string) ([]*spec.ClusterStatus, error) {
c.clustersMu.RLock()

clusterNames, ok := c.teamClusters[team]
if !ok {
c.clustersMu.RUnlock()
return nil, fmt.Errorf("could not find clusters for the team")
}

var resp = make([]*spec.ClusterStatus, len(clusterNames))
for i, clName := range clusterNames {
cl := c.clusters[clName]

resp[i] = cl.GetStatus()
resp[i].Worker = c.clusterWorkerID(clName)

}
c.clustersMu.RUnlock()

return resp, nil
// TeamClusterList returns team-clusters map
func (c *Controller) TeamClusterList() map[string][]spec.NamespacedName {
return c.teamClusters
}

// GetConfig returns controller config
Expand Down

0 comments on commit 646aae0

Please sign in to comment.