From fc44dcea177da11382986ec774046ae5ae500595 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 30 Oct 2024 16:02:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(host):=20=E5=AE=B9=E5=99=A8=E5=8D=A1?= =?UTF-8?q?=E5=9C=A8=20probing=20=E7=8A=B6=E6=80=81=20(#21497)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/hostman/container/status/status_manager.go | 3 +++ pkg/hostman/guestman/pod.go | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/hostman/container/status/status_manager.go b/pkg/hostman/container/status/status_manager.go index 50d55f40d6..e801239d68 100644 --- a/pkg/hostman/container/status/status_manager.go +++ b/pkg/hostman/container/status/status_manager.go @@ -17,6 +17,7 @@ package status import ( "context" + "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/onecloud/pkg/apis" @@ -50,5 +51,7 @@ func (m *manager) SetContainerStartup(podId string, containerId string, started } if _, err := hostutils.UpdateContainerStatus(context.Background(), containerId, input); err != nil { log.Errorf("set container(%s/%s) status failed: %s", podId, containerId, err) + } else { + log.Infof("set container(%s/%s) status to %s", podId, containerId, jsonutils.Marshal(input).String()) } } diff --git a/pkg/hostman/guestman/pod.go b/pkg/hostman/guestman/pod.go index 629fbd07f0..17ae8232b9 100644 --- a/pkg/hostman/guestman/pod.go +++ b/pkg/hostman/guestman/pod.go @@ -396,6 +396,8 @@ func (s *sPodGuestInstance) SyncStatus(reason string) { if _, err := hostutils.UpdateContainerStatus(ctx, c.Id, ctrStatusInput); err != nil { log.Errorf("failed update container %s status: %s", c.Id, err) } + // 同步容器状态可能会出现 probing 状态,所以需要 mark 成 dirty,等待 probe manager 重新探测容器状态 + s.markContainerProbeDirty(cStatus, c.Id, reason) status = GetPodStatusByContainerStatus(status, cStatus) } @@ -1850,15 +1852,19 @@ func (s *sPodGuestInstance) getContainerStatus(ctx context.Context, ctrId string return status, cs, nil } +func (s *sPodGuestInstance) markContainerProbeDirty(status, ctrId string, reason string) { + if status == computeapi.CONTAINER_STATUS_PROBING { + log.Infof("mark container %s to dirty: %s", ctrId, reason) + s.getProbeManager().SetDirtyContainer(ctrId) + } +} + func (s *sPodGuestInstance) SyncContainerStatus(ctx context.Context, userCred mcclient.TokenCredential, ctrId string) (jsonutils.JSONObject, error) { status, cs, err := s.getContainerStatus(ctx, ctrId) if err != nil { return nil, errors.Wrap(err, "get container status") } - if status == computeapi.CONTAINER_STATUS_PROBING { - log.Infof("mark container %s to dirty after syncing status", ctrId) - s.getProbeManager().SetDirtyContainer(ctrId) - } + s.markContainerProbeDirty(status, ctrId, "after syncing status") resp := computeapi.ContainerSyncStatusResponse{ Status: status, }