From ad4d0abd41f3bd8abc5c7a0d79d8e574e286489b Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Fri, 14 Jun 2024 19:19:12 +0800 Subject: [PATCH] feat(region): add container info into server details (#20544) --- pkg/apis/compute/guests.go | 9 +++++++++ pkg/compute/models/guests.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 4cd529dc21..50269655d3 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -274,6 +274,15 @@ type ServerDetails struct { // 监控上报URL MonitorUrl string `json:"monitor_url"` + + // 容器描述信息 + Containers []*PodContainerDesc `json:"containers"` +} + +type PodContainerDesc struct { + Id string `json:"id"` + Name string `json:"name"` + Image string `json:"image"` } type Floppy struct { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index e533e772be..b3fc6a43fd 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -2612,6 +2612,22 @@ func (self *SGuest) moreExtraInfo( out.MonitorUrl = drv.FetchMonitorUrl(ctx, self) } + if drv != nil && drv.GetHypervisor() == api.HYPERVISOR_POD { + ctrs, _ := GetContainerManager().GetContainersByPod(self.GetId()) + desc := make([]*api.PodContainerDesc, len(ctrs)) + for i := range ctrs { + ctr := ctrs[i] + desc[i] = &api.PodContainerDesc{ + Id: ctr.GetId(), + Name: ctr.GetName(), + } + if ctr.Spec != nil { + desc[i].Image = ctr.Spec.Image + } + } + out.Containers = desc + } + return out }