获取应用的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,24 +32,37 @@ func (l *GetAppPodsByAppNameLogic) GetAppPodsByAppName(in *kubernetes.AppDetailR
details := make([]*kubernetes.PodDetail, 0) details := make([]*kubernetes.PodDetail, 0)
//查询指定集群下指定命名空间下和名字的deployment详情 //查询指定集群下指定命名空间下和名字的deployment详情
for k, _ := range pkg.KClients { for k, _ := range pkg.KClients {
appDetail := kubernetes.PodDetail{
ClusterName: k,
}
storeAmount := 0
appSelector := fmt.Sprintf("app=%s", in.Name) appSelector := fmt.Sprintf("app=%s", in.Name)
KPodList := []*kubernetes.Pod{} var KPodList []*kubernetes.Pod
//查询pods //查询pods
pods, err := pkg.KClients[k].ClientSet.CoreV1().Pods(in.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: appSelector}) pods, err := pkg.KClients[k].ClientSet.CoreV1().Pods(in.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: appSelector})
if err != nil { if err != nil {
return &kubernetes.PodDetailResp{ return &kubernetes.PodDetailResp{
Code: "200", Code: "500",
Msg: err.Error(), Msg: err.Error(),
}, err }, 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 { if len(pods.Items) > 0 {
tool.Convert(pods.Items, &KPodList) tool.Convert(pods.Items, &KPodList)
appDetail := kubernetes.PodDetail{ appDetail.Items = KPodList
ClusterName: k,
Items: KPodList,
}
details = append(details, &appDetail)
} }
details = append(details, &appDetail)
} }
return &kubernetes.PodDetailResp{ return &kubernetes.PodDetailResp{

File diff suppressed because it is too large Load Diff

View File

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