Browse code

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>

Lei Jitang authored on 2016/04/15 10:40:20
Showing 2 changed files
... ...
@@ -120,7 +120,7 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
120 120
 		if st.State == StateExit && ctr.restartManager != nil {
121 121
 			restart, wait, err := ctr.restartManager.ShouldRestart(e.Status, false)
122 122
 			if err != nil {
123
-				logrus.Error(err)
123
+				logrus.Warnf("container %s %v", ctr.containerID, err)
124 124
 			} else if restart {
125 125
 				st.State = StateRestart
126 126
 				ctr.restarting = true
... ...
@@ -42,6 +42,9 @@ func (rm *restartManager) SetPolicy(policy container.RestartPolicy) {
42 42
 }
43 43
 
44 44
 func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped bool) (bool, chan error, error) {
45
+	if rm.policy.IsNone() {
46
+		return false, nil, nil
47
+	}
45 48
 	rm.Lock()
46 49
 	unlockOnExit := true
47 50
 	defer func() {