2018-02-05 21:05:59 +00:00
|
|
|
package service // import "github.com/docker/docker/integration/service"
|
2017-08-29 06:49:26 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2018-06-01 10:47:38 +00:00
|
|
|
"fmt"
|
2018-01-28 07:15:44 +00:00
|
|
|
"io/ioutil"
|
2017-08-29 06:49:26 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2018-02-02 22:36:59 +00:00
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
2017-08-29 06:49:26 +00:00
|
|
|
"github.com/docker/docker/client"
|
2018-02-09 18:13:26 +00:00
|
|
|
"github.com/docker/docker/integration/internal/swarm"
|
2018-06-01 10:47:38 +00:00
|
|
|
"github.com/docker/docker/internal/test/daemon"
|
2018-06-11 13:32:11 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/poll"
|
2017-08-29 06:49:26 +00:00
|
|
|
)
|
|
|
|
|
2018-06-01 10:47:38 +00:00
|
|
|
func TestServiceCreateInit(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
|
|
|
t.Run("daemonInitDisabled", testServiceCreateInit(false))
|
|
|
|
t.Run("daemonInitEnabled", testServiceCreateInit(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testServiceCreateInit(daemonEnabled bool) func(t *testing.T) {
|
|
|
|
return func(t *testing.T) {
|
|
|
|
var ops = []func(*daemon.Daemon){}
|
|
|
|
|
|
|
|
if daemonEnabled {
|
|
|
|
ops = append(ops, daemon.WithInit)
|
|
|
|
}
|
|
|
|
d := swarm.NewSwarm(t, testEnv, ops...)
|
|
|
|
defer d.Stop(t)
|
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
booleanTrue := true
|
|
|
|
booleanFalse := false
|
|
|
|
|
|
|
|
serviceID := swarm.CreateService(t, d)
|
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, 1), swarm.ServicePoll)
|
|
|
|
i := inspectServiceContainer(t, client, serviceID)
|
|
|
|
// HostConfig.Init == nil means that it delegates to daemon configuration
|
|
|
|
assert.Check(t, i.HostConfig.Init == nil)
|
|
|
|
|
|
|
|
serviceID = swarm.CreateService(t, d, swarm.ServiceWithInit(&booleanTrue))
|
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, 1), swarm.ServicePoll)
|
|
|
|
i = inspectServiceContainer(t, client, serviceID)
|
|
|
|
assert.Check(t, is.Equal(true, *i.HostConfig.Init))
|
|
|
|
|
|
|
|
serviceID = swarm.CreateService(t, d, swarm.ServiceWithInit(&booleanFalse))
|
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, 1), swarm.ServicePoll)
|
|
|
|
i = inspectServiceContainer(t, client, serviceID)
|
|
|
|
assert.Check(t, is.Equal(false, *i.HostConfig.Init))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func inspectServiceContainer(t *testing.T, client client.APIClient, serviceID string) types.ContainerJSON {
|
|
|
|
t.Helper()
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("label", fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID))
|
|
|
|
containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{Filters: filter})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Len(containers, 1))
|
|
|
|
|
|
|
|
i, err := client.ContainerInspect(context.Background(), containers[0].ID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2017-11-07 06:12:03 +00:00
|
|
|
func TestCreateServiceMultipleTimes(t *testing.T) {
|
2017-08-29 06:49:26 +00:00
|
|
|
defer setupTest(t)()
|
2018-02-02 22:36:59 +00:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2017-08-29 06:49:26 +00:00
|
|
|
defer d.Stop(t)
|
2018-04-13 15:02:56 +00:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2017-08-29 06:49:26 +00:00
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
overlayName := "overlay1_" + t.Name()
|
2017-08-29 06:49:26 +00:00
|
|
|
networkCreate := types.NetworkCreate{
|
|
|
|
CheckDuplicate: true,
|
|
|
|
Driver: "overlay",
|
|
|
|
}
|
|
|
|
|
|
|
|
netResp, err := client.NetworkCreate(context.Background(), overlayName, networkCreate)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 06:49:26 +00:00
|
|
|
overlayID := netResp.ID
|
|
|
|
|
2017-11-07 06:12:03 +00:00
|
|
|
var instances uint64 = 4
|
2017-08-29 06:49:26 +00:00
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
serviceName := "TestService_" + t.Name()
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceSpec := []swarm.ServiceSpecOpt{
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
2018-06-07 15:55:08 +00:00
|
|
|
swarm.ServiceWithName(serviceName),
|
2018-05-10 09:45:11 +00:00
|
|
|
swarm.ServiceWithNetwork(overlayName),
|
|
|
|
}
|
2017-08-29 06:49:26 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceID := swarm.CreateService(t, d, serviceSpec...)
|
2018-03-27 04:06:46 +00:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
2017-08-29 06:49:26 +00:00
|
|
|
|
|
|
|
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 06:49:26 +00:00
|
|
|
|
|
|
|
err = client.ServiceRemove(context.Background(), serviceID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 06:49:26 +00:00
|
|
|
|
2018-03-27 04:06:46 +00:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2017-11-07 06:12:03 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceID2 := swarm.CreateService(t, d, serviceSpec...)
|
2018-03-27 04:06:46 +00:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll)
|
2017-11-07 06:12:03 +00:00
|
|
|
|
|
|
|
err = client.ServiceRemove(context.Background(), serviceID2)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-11-07 06:12:03 +00:00
|
|
|
|
2018-03-27 04:06:46 +00:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID2), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2017-11-07 06:12:03 +00:00
|
|
|
|
2017-08-29 06:49:26 +00:00
|
|
|
err = client.NetworkRemove(context.Background(), overlayID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-08-29 06:49:26 +00:00
|
|
|
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
}
|
|
|
|
|
2017-10-31 20:05:24 +00:00
|
|
|
func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 22:36:59 +00:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2017-10-31 20:05:24 +00:00
|
|
|
defer d.Stop(t)
|
2018-04-13 15:02:56 +00:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2017-10-31 20:05:24 +00:00
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
name := "foo_" + t.Name()
|
2017-10-31 20:05:24 +00:00
|
|
|
networkCreate := types.NetworkCreate{
|
|
|
|
CheckDuplicate: false,
|
|
|
|
Driver: "bridge",
|
|
|
|
}
|
|
|
|
|
|
|
|
n1, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
n2, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Dupliates with name but with different driver
|
|
|
|
networkCreate.Driver = "overlay"
|
|
|
|
n3, err := client.NetworkCreate(context.Background(), name, networkCreate)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Create Service with the same name
|
|
|
|
var instances uint64 = 1
|
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
serviceName := "top_" + t.Name()
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
2018-06-07 15:55:08 +00:00
|
|
|
swarm.ServiceWithName(serviceName),
|
2018-05-10 09:45:11 +00:00
|
|
|
swarm.ServiceWithNetwork(name),
|
|
|
|
)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
resp, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target))
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Remove Service
|
2018-05-10 09:45:11 +00:00
|
|
|
err = client.ServiceRemove(context.Background(), serviceID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Make sure task has been destroyed.
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Remove networks
|
|
|
|
err = client.NetworkRemove(context.Background(), n3.ID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
err = client.NetworkRemove(context.Background(), n2.ID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
err = client.NetworkRemove(context.Background(), n1.ID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-31 20:05:24 +00:00
|
|
|
|
|
|
|
// Make sure networks have been destroyed.
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n3.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n2.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
poll.WaitOn(t, networkIsRemoved(client, n1.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
|
|
|
|
}
|
|
|
|
|
2018-01-28 07:15:44 +00:00
|
|
|
func TestCreateServiceSecretFileMode(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 22:36:59 +00:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-01-28 07:15:44 +00:00
|
|
|
defer d.Stop(t)
|
2018-04-13 15:02:56 +00:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2018-06-07 15:55:08 +00:00
|
|
|
secretName := "TestSecret_" + t.Name()
|
2018-02-02 22:36:59 +00:00
|
|
|
secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-06-07 15:55:08 +00:00
|
|
|
Name: secretName,
|
2018-01-28 07:15:44 +00:00
|
|
|
},
|
|
|
|
Data: []byte("TESTSECRET"),
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
2018-06-07 15:55:08 +00:00
|
|
|
serviceName := "TestService_" + t.Name()
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
2018-06-07 15:55:08 +00:00
|
|
|
swarm.ServiceWithName(serviceName),
|
2018-05-10 09:45:11 +00:00
|
|
|
swarm.ServiceWithCommand([]string{"/bin/sh", "-c", "ls -l /etc/secret || /bin/top"}),
|
|
|
|
swarm.ServiceWithSecret(&swarmtypes.SecretReference{
|
|
|
|
File: &swarmtypes.SecretReferenceFileTarget{
|
|
|
|
Name: "/etc/secret",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0777,
|
2018-01-28 07:15:44 +00:00
|
|
|
},
|
2018-05-10 09:45:11 +00:00
|
|
|
SecretID: secretResp.ID,
|
2018-06-07 15:55:08 +00:00
|
|
|
SecretName: secretName,
|
2018-05-10 09:45:11 +00:00
|
|
|
}),
|
|
|
|
)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
filter := filters.NewArgs()
|
2018-05-10 09:45:11 +00:00
|
|
|
filter.Add("service", serviceID)
|
2018-01-28 07:15:44 +00:00
|
|
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(tasks), 1))
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
|
|
|
|
ShowStdout: true,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
content, err := ioutil.ReadAll(body)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
err = client.ServiceRemove(ctx, serviceID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
2018-03-27 04:06:46 +00:00
|
|
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
err = client.SecretRemove(ctx, secretName)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateServiceConfigFileMode(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 22:36:59 +00:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-01-28 07:15:44 +00:00
|
|
|
defer d.Stop(t)
|
2018-04-13 15:02:56 +00:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2018-06-07 15:55:08 +00:00
|
|
|
configName := "TestConfig_" + t.Name()
|
2018-02-02 22:36:59 +00:00
|
|
|
configResp, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
2018-06-07 15:55:08 +00:00
|
|
|
Name: configName,
|
2018-01-28 07:15:44 +00:00
|
|
|
},
|
|
|
|
Data: []byte("TESTCONFIG"),
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
2018-06-07 15:55:08 +00:00
|
|
|
serviceName := "TestService_" + t.Name()
|
2018-05-10 09:45:11 +00:00
|
|
|
serviceID := swarm.CreateService(t, d,
|
2018-06-07 15:55:08 +00:00
|
|
|
swarm.ServiceWithName(serviceName),
|
2018-05-10 09:45:11 +00:00
|
|
|
swarm.ServiceWithCommand([]string{"/bin/sh", "-c", "ls -l /etc/config || /bin/top"}),
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
|
|
|
swarm.ServiceWithConfig(&swarmtypes.ConfigReference{
|
|
|
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
|
|
|
Name: "/etc/config",
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
|
|
|
Mode: 0777,
|
2018-01-28 07:15:44 +00:00
|
|
|
},
|
2018-05-10 09:45:11 +00:00
|
|
|
ConfigID: configResp.ID,
|
2018-06-07 15:55:08 +00:00
|
|
|
ConfigName: configName,
|
2018-05-10 09:45:11 +00:00
|
|
|
}),
|
|
|
|
)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances))
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
filter := filters.NewArgs()
|
2018-05-10 09:45:11 +00:00
|
|
|
filter.Add("service", serviceID)
|
2018-01-28 07:15:44 +00:00
|
|
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(tasks), 1))
|
2018-01-28 07:15:44 +00:00
|
|
|
|
|
|
|
body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
|
|
|
|
ShowStdout: true,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
content, err := ioutil.ReadAll(body)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
err = client.ServiceRemove(ctx, serviceID)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
|
2018-05-10 09:45:11 +00:00
|
|
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID))
|
2018-01-28 07:15:44 +00:00
|
|
|
poll.WaitOn(t, noTasks(client))
|
|
|
|
|
2018-06-07 15:55:08 +00:00
|
|
|
err = client.ConfigRemove(ctx, configName)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-01-28 07:15:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 06:49:26 +00:00
|
|
|
func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceID)
|
|
|
|
tasks, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return poll.Error(err)
|
|
|
|
case len(tasks) == int(instances):
|
|
|
|
for _, task := range tasks {
|
2018-02-02 22:36:59 +00:00
|
|
|
if task.Status.State != swarmtypes.TaskStateRunning {
|
2017-08-29 06:49:26 +00:00
|
|
|
return poll.Continue("waiting for tasks to enter run state")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
default:
|
|
|
|
return poll.Continue("task count at %d waiting for %d", len(tasks), instances)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 06:12:03 +00:00
|
|
|
func noTasks(client client.ServiceAPIClient) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
tasks, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return poll.Error(err)
|
|
|
|
case len(tasks) == 0:
|
|
|
|
return poll.Success()
|
|
|
|
default:
|
|
|
|
return poll.Continue("task count at %d waiting for 0", len(tasks))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 06:49:26 +00:00
|
|
|
func serviceIsRemoved(client client.ServiceAPIClient, serviceID string) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("service", serviceID)
|
|
|
|
_, err := client.TaskList(context.Background(), types.TaskListOptions{
|
|
|
|
Filters: filter,
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
return poll.Continue("waiting for service %s to be deleted", serviceID)
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func networkIsRemoved(client client.NetworkAPIClient, networkID string) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
_, err := client.NetworkInspect(context.Background(), networkID, types.NetworkInspectOptions{})
|
|
|
|
if err == nil {
|
|
|
|
return poll.Continue("waiting for network %s to be removed", networkID)
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
}
|