1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #36924 from runcom/fix-created-rp

restartmanager: do not apply restart policy on created containers
This commit is contained in:
Sebastiaan van Stijn 2018-04-25 21:48:01 +02:00 committed by GitHub
commit 18bfe3c128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -320,7 +320,7 @@ func (daemon *Daemon) restore() error {
// not initialized yet. We will start // not initialized yet. We will start
// it after the cluster is // it after the cluster is
// initialized. // initialized.
if daemon.configStore.AutoRestart && c.ShouldRestart() && !c.NetworkSettings.HasSwarmEndpoint { if daemon.configStore.AutoRestart && c.ShouldRestart() && !c.NetworkSettings.HasSwarmEndpoint && c.HasBeenStartedBefore {
mapLock.Lock() mapLock.Lock()
restartContainers[c] = make(chan struct{}) restartContainers[c] = make(chan struct{})
mapLock.Unlock() mapLock.Unlock()
@ -450,7 +450,7 @@ func (daemon *Daemon) RestartSwarmContainers() {
// Autostart all the containers which has a // Autostart all the containers which has a
// swarm endpoint now that the cluster is // swarm endpoint now that the cluster is
// initialized. // initialized.
if daemon.configStore.AutoRestart && c.ShouldRestart() && c.NetworkSettings.HasSwarmEndpoint { if daemon.configStore.AutoRestart && c.ShouldRestart() && c.NetworkSettings.HasSwarmEndpoint && c.HasBeenStartedBefore {
group.Add(1) group.Add(1)
go func(c *container.Container) { go func(c *container.Container) {
defer group.Done() defer group.Done()

View file

@ -22,6 +22,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
xRunning bool xRunning bool
xRunningLiveRestore bool xRunningLiveRestore bool
xStart bool
} }
for _, c := range []testCase{ for _, c := range []testCase{
@ -29,6 +30,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
desc: "container without restart policy", desc: "container without restart policy",
config: &container.Config{Image: "busybox", Cmd: []string{"top"}}, config: &container.Config{Image: "busybox", Cmd: []string{"top"}},
xRunningLiveRestore: true, xRunningLiveRestore: true,
xStart: true,
}, },
{ {
desc: "container with restart=always", desc: "container with restart=always",
@ -36,6 +38,12 @@ func TestDaemonRestartKillContainers(t *testing.T) {
hostConfig: &container.HostConfig{RestartPolicy: container.RestartPolicy{Name: "always"}}, hostConfig: &container.HostConfig{RestartPolicy: container.RestartPolicy{Name: "always"}},
xRunning: true, xRunning: true,
xRunningLiveRestore: true, xRunningLiveRestore: true,
xStart: true,
},
{
desc: "container created should not be restarted",
config: &container.Config{Image: "busybox", Cmd: []string{"top"}},
hostConfig: &container.HostConfig{RestartPolicy: container.RestartPolicy{Name: "always"}},
}, },
} { } {
for _, liveRestoreEnabled := range []bool{false, true} { for _, liveRestoreEnabled := range []bool{false, true} {
@ -72,8 +80,10 @@ func TestDaemonRestartKillContainers(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true}) defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) if c.xStart {
assert.NilError(t, err) err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
assert.NilError(t, err)
}
stopDaemon(t, d) stopDaemon(t, d)
d.Start(t, args...) d.Start(t, args...)