获取应用的Pod增加存储字段

This commit is contained in:
devad 2023-11-27 19:32:07 +08:00
parent bdebaff6f7
commit 0f0242e33b
3 changed files with 5125 additions and 5101 deletions

View File

@ -32,25 +32,38 @@ func (l *GetAppPodsByAppNameLogic) GetAppPodsByAppName(in *kubernetes.AppDetailR
details := make([]*kubernetes.PodDetail, 0)
//查询指定集群下指定命名空间下和名字的deployment详情
for k, _ := range pkg.KClients {
appDetail := kubernetes.PodDetail{
ClusterName: k,
}
storeAmount := 0
appSelector := fmt.Sprintf("app=%s", in.Name)
KPodList := []*kubernetes.Pod{}
var KPodList []*kubernetes.Pod
//查询pods
pods, err := pkg.KClients[k].ClientSet.CoreV1().Pods(in.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: appSelector})
if err != nil {
return &kubernetes.PodDetailResp{
Code: "200",
Code: "500",
Msg: err.Error(),
}, err
}
//查询指定集群下指定命名空间下和名字的statefulSets详情
statefulSets, _ := pkg.KClients[k].ClientSet.AppsV1().StatefulSets(in.Namespace).Get(context.Background(), in.Name, metav1.GetOptions{})
//计算存储卷大小
if statefulSets.Spec.VolumeClaimTemplates != nil {
//存储卷大小求和
for k := range statefulSets.Spec.VolumeClaimTemplates {
storeAmount += int(statefulSets.Spec.VolumeClaimTemplates[k].Spec.Resources.Requests.Storage().Value())
}
storeAmount = storeAmount / 1024 / 1024 / 1024
appDetail.StoreAmount = int64(storeAmount)
}
if len(pods.Items) > 0 {
tool.Convert(pods.Items, &KPodList)
appDetail := kubernetes.PodDetail{
ClusterName: k,
Items: KPodList,
appDetail.Items = KPodList
}
details = append(details, &appDetail)
}
}
return &kubernetes.PodDetailResp{
Code: "200",

File diff suppressed because it is too large Load Diff

View File

@ -143,7 +143,8 @@ message AppDetail {
message PodDetail {
string clusterName = 1; //
repeated Pod podList = 2; //pod列表
repeated Pod items = 2; //pod列表
int64 storeAmount = 3; //使Gi
}
message PodDetailResp {