Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 9b4e438

Browse files
committed
do not treat starting a running container as failure
Signed-off-by: Wang Xu <gnawux@gmail.com>
1 parent 054ccaf commit 9b4e438

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

daemon/pod/container.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/docker/engine-api/types/strslice"
2121

2222
"github.com/hyperhq/hypercontainer-utils/hlog"
23+
"github.com/hyperhq/hyperd/errors"
2324
apitypes "github.com/hyperhq/hyperd/types"
2425
"github.com/hyperhq/hyperd/utils"
2526
runv "github.com/hyperhq/runv/api"
@@ -233,6 +234,11 @@ func (c *Container) Add() error {
233234

234235
func (c *Container) start() error {
235236
if err := c.status.Start(); err != nil {
237+
if err == errors.ErrContainerAlreadyRunning {
238+
err = nil
239+
c.Log(INFO, "container in running state, do not need start")
240+
return nil
241+
}
236242
c.Log(ERROR, err)
237243
return err
238244
}
@@ -1196,8 +1202,10 @@ func (cs *ContainerStatus) Start() error {
11961202
cs.Lock()
11971203
defer cs.Unlock()
11981204

1199-
if cs.State != S_CONTAINER_CREATED {
1200-
return fmt.Errorf("only CREATING container could be set to creatd, current: %d", cs.State)
1205+
if cs.State == S_CONTAINER_RUNNING {
1206+
return errors.ErrContainerAlreadyRunning
1207+
} else if cs.State != S_CONTAINER_CREATED {
1208+
return fmt.Errorf("only CREATED container could be set to creatd, current: %d", cs.State)
12011209
}
12021210

12031211
cs.Killed = false

errors/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ var (
2626
Message: "cannot complete the operation, because the pod %s is not running",
2727
HTTPStatusCode: http.StatusPreconditionFailed,
2828
})
29+
30+
ErrContainerAlreadyRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
31+
Value: "HYPER_CONTAINER_RUNNING",
32+
Message: "container %s is in running state",
33+
HTTPStatusCode: http.StatusPreconditionFailed,
34+
})
2935
)

0 commit comments

Comments
 (0)