Skip to content

Commit a8a5ff9

Browse files
authored
fix(host): clear the rootfs of container before starting (#23360)
1 parent 0d77ff8 commit a8a5ff9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pkg/hostman/guestman/pod.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,9 @@ func (s *sPodGuestInstance) StartContainer(ctx context.Context, userCred mcclien
12961296
}
12971297
}
12981298
}
1299+
if err := s.clearContainerRootFs(ctrId, input.Spec.Rootfs); err != nil {
1300+
return nil, errors.Wrapf(err, "clear container rootfs %s before starting", jsonutils.Marshal(input.Spec.Rootfs))
1301+
}
12991302
if !hasCtr || needRecreate {
13001303
log.Infof("recreate container %s before starting. hasCtr: %v, needRecreate: %v", ctrId, hasCtr, needRecreate)
13011304
// delete and recreate the container before starting
@@ -1497,11 +1500,6 @@ func (s *sPodGuestInstance) StopContainer(ctx context.Context, userCred mcclient
14971500
// 后期可以添加主动通知刷新
14981501
time.Sleep(2 * time.Second)
14991502
}
1500-
if ctr := s.GetContainerById(ctrId); ctr != nil {
1501-
if err := s.clearContainerRootFs(ctrId, ctr.Spec.Rootfs); err != nil {
1502-
return nil, errors.Wrapf(err, "clear container rootfs %s", jsonutils.Marshal(ctr.Spec.Rootfs))
1503-
}
1504-
}
15051503
if err := s.startStat.RemoveContainerFile(ctrId); err != nil {
15061504
return nil, errors.Wrap(err, "startStat.RemoveContainerFile")
15071505
}

0 commit comments

Comments
 (0)