pcm-coordinator/internal/logic/cloud/podslistlogic.go

50 lines
1.3 KiB
Go

package cloud
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
v1 "k8s.io/api/core/v1"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
type PodsListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
type ParticipantResp struct {
Code int `json:"code"`
Msg string `json:"message"`
Data *v1.PodList `json:"data"` // 改成结构体
}
func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsListLogic {
return &PodsListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PodsListLogic) PodsList(req *types.PodsListReq) (resp *types.PodsListResp, err error) {
resp = &types.PodsListResp{}
// query cluster http url.
var apiServerList []string
l.svcCtx.DbEngin.Raw("select server from t_adapter where resource_type = '01'").Scan(&apiServerList)
for _, server := range apiServerList {
participantResp := ParticipantResp{}
param := map[string]string{
"clusterName": req.ClusterName,
}
httputils.HttpGetWithResult(param, server+"/api/v1/pod/list", &participantResp)
resp.Data = append(resp.Data, participantResp.Data)
}
return resp, nil
}