浏览代码

Don't throw "restartmanager canceled" error for no restart policy container

Don't throw "restartmanager canceled" error for no restart policy container
and add the container id to the warning message if a container has restart policy
and has been canceled.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
(cherry picked from commit 494297baf8f391ce73cdc2e885a335a266261970)
Lei Jitang 9 年之前
父节点
当前提交
c9417489a2
共有 2 个文件被更改,包括 4 次插入1 次删除
  1. 1 1
      libcontainerd/container_linux.go
  2. 3 0
      restartmanager/restartmanager.go

+ 1 - 1
libcontainerd/container_linux.go

@@ -117,7 +117,7 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
 		if st.State == StateExit && ctr.restartManager != nil {
 			restart, wait, err := ctr.restartManager.ShouldRestart(e.Status)
 			if err != nil {
-				logrus.Error(err)
+				logrus.Warnf("container %s %v", ctr.containerID, err)
 			} else if restart {
 				st.State = StateRestart
 				ctr.restarting = true

+ 3 - 0
restartmanager/restartmanager.go

@@ -42,6 +42,9 @@ func (rm *restartManager) SetPolicy(policy container.RestartPolicy) {
 }
 
 func (rm *restartManager) ShouldRestart(exitCode uint32) (bool, chan error, error) {
+	if rm.policy.IsNone() {
+		return false, nil, nil
+	}
 	rm.Lock()
 	unlockOnExit := true
 	defer func() {