From b7a3ed9e2735b246484eecdf86b2bdb55da9b976 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 24 Sep 2025 18:52:06 +0800 Subject: [PATCH] fix(host): clear the rootfs of container before starting (#23361) --- pkg/hostman/guestman/pod.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/hostman/guestman/pod.go b/pkg/hostman/guestman/pod.go index dfe4f269dc..5d90ec0b44 100644 --- a/pkg/hostman/guestman/pod.go +++ b/pkg/hostman/guestman/pod.go @@ -1296,6 +1296,9 @@ func (s *sPodGuestInstance) StartContainer(ctx context.Context, userCred mcclien } } } + if err := s.clearContainerRootFs(ctrId, input.Spec.Rootfs); err != nil { + return nil, errors.Wrapf(err, "clear container rootfs %s before starting", jsonutils.Marshal(input.Spec.Rootfs)) + } if !hasCtr || needRecreate { log.Infof("recreate container %s before starting. hasCtr: %v, needRecreate: %v", ctrId, hasCtr, needRecreate) // delete and recreate the container before starting @@ -1497,11 +1500,6 @@ func (s *sPodGuestInstance) StopContainer(ctx context.Context, userCred mcclient // 后期可以添加主动通知刷新 time.Sleep(2 * time.Second) } - if ctr := s.GetContainerById(ctrId); ctr != nil { - if err := s.clearContainerRootFs(ctrId, ctr.Spec.Rootfs); err != nil { - return nil, errors.Wrapf(err, "clear container rootfs %s", jsonutils.Marshal(ctr.Spec.Rootfs)) - } - } if err := s.startStat.RemoveContainerFile(ctrId); err != nil { return nil, errors.Wrap(err, "startStat.RemoveContainerFile") }