Merge pull request #411 from GLYASAI/allpods

[FIX] failed to listing pods
This commit is contained in:
barnettZQG 2019-08-31 04:43:41 -05:00 committed by GitHub
commit 12304c7e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -21,8 +21,11 @@ package controller
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/worker/server"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/handler"
@ -55,9 +58,23 @@ type PodController struct{}
// "$ref": "#/responses/commandResponse"
// description: get some service pods
func Pods(w http.ResponseWriter, r *http.Request) {
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
pods, _ := handler.GetServiceManager().GetPods(serviceID)
httputil.ReturnSuccess(r, w, pods)
serviceIDs := strings.Split(r.FormValue("service_ids"), ",")
if serviceIDs == nil || len(serviceIDs) == 0 {
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*model.Tenants)
services, _ := db.GetManager().TenantServiceDao().GetServicesByTenantID(tenant.UUID)
for _, s := range services {
serviceIDs = append(serviceIDs, s.ServiceID)
}
}
var allpods []*handler.K8sPodInfo
for _, serviceID := range serviceIDs {
podinfo, _ := handler.GetServiceManager().GetPods(serviceID)
ps := append(podinfo.NewPods, podinfo.OldPods...)
for _, pod := range ps {
allpods = append(allpods, pod)
}
}
httputil.ReturnSuccess(r, w, allpods)
}
// PodDetail -

View File

@ -1712,6 +1712,7 @@ type K8sPodInfo struct {
PodName string `json:"pod_name"`
PodIP string `json:"pod_ip"`
PodStatus string `json:"pod_status"`
ServiceID string `json:"service_id"`
Container map[string]map[string]string `json:"container"`
}
@ -1734,6 +1735,7 @@ func (s *ServiceAction) GetPods(serviceID string) (*K8sPodInfos, error) {
podInfo.PodName = v.PodName
podInfo.PodIP = v.PodIp
podInfo.PodStatus = v.PodStatus
podInfo.ServiceID = serviceID
containerInfos := make(map[string]map[string]string, 10)
for _, container := range v.Containers {
containerInfos[container.ContainerName] = map[string]string{