It should not be an error to call a common option to cancel restarts.
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
"github.com/Sirupsen/logrus" |
| 11 | 11 |
containerd "github.com/docker/containerd/api/grpc/types" |
| 12 |
+ "github.com/docker/docker/restartmanager" |
|
| 12 | 13 |
"github.com/opencontainers/specs/specs-go" |
| 13 | 14 |
"golang.org/x/net/context" |
| 14 | 15 |
) |
| ... | ... |
@@ -135,7 +136,9 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
|
| 135 | 135 |
logrus.Error(err) |
| 136 | 136 |
} |
| 137 | 137 |
}) |
| 138 |
- logrus.Error(err) |
|
| 138 |
+ if err != restartmanager.ErrRestartCanceled {
|
|
| 139 |
+ logrus.Error(err) |
|
| 140 |
+ } |
|
| 139 | 141 |
} else {
|
| 140 | 142 |
ctr.start() |
| 141 | 143 |
} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package restartmanager |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"sync" |
| 6 | 7 |
"time" |
| ... | ... |
@@ -13,6 +14,10 @@ const ( |
| 13 | 13 |
defaultTimeout = 100 * time.Millisecond |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
+// ErrRestartCanceled is returned when the restart manager has been |
|
| 17 |
+// canceled and will no longer restart the container. |
|
| 18 |
+var ErrRestartCanceled = errors.New("restart canceled")
|
|
| 19 |
+ |
|
| 16 | 20 |
// RestartManager defines object that controls container restarting rules. |
| 17 | 21 |
type RestartManager interface {
|
| 18 | 22 |
Cancel() error |
| ... | ... |
@@ -54,7 +59,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped |
| 54 | 54 |
}() |
| 55 | 55 |
|
| 56 | 56 |
if rm.canceled {
|
| 57 |
- return false, nil, fmt.Errorf("restartmanager canceled")
|
|
| 57 |
+ return false, nil, ErrRestartCanceled |
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
if rm.active {
|
| ... | ... |
@@ -95,7 +100,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped |
| 95 | 95 |
go func() {
|
| 96 | 96 |
select {
|
| 97 | 97 |
case <-rm.cancel: |
| 98 |
- ch <- fmt.Errorf("restartmanager canceled")
|
|
| 98 |
+ ch <- ErrRestartCanceled |
|
| 99 | 99 |
close(ch) |
| 100 | 100 |
case <-time.After(rm.timeout): |
| 101 | 101 |
rm.Lock() |