mirror of https://github.com/docker/docs.git
Merge pull request #1141 from vieux/only_display_swarm_containers
display only containers created by swarm in mesos
This commit is contained in:
commit
11b12b81b0
|
|
@ -243,7 +243,11 @@ func (c *Cluster) Containers() cluster.Containers {
|
|||
out := cluster.Containers{}
|
||||
for _, s := range c.slaves {
|
||||
for _, container := range s.engine.Containers() {
|
||||
out = append(out, formatContainer(container))
|
||||
if container.Config.Labels != nil {
|
||||
if _, ok := container.Config.Labels[cluster.SwarmLabelNamespace+".mesos.task"]; ok {
|
||||
out = append(out, formatContainer(container))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ func TestContainerLookup(t *testing.T) {
|
|||
},
|
||||
Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{
|
||||
Labels: map[string]string{
|
||||
"com.docker.swarm.id": "swarm1-id",
|
||||
"com.docker.swarm.mesos.task": "task1-id",
|
||||
"com.docker.swarm.mesos.name": "container1-name1",
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
|
@ -44,14 +45,26 @@ func TestContainerLookup(t *testing.T) {
|
|||
},
|
||||
Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{
|
||||
Labels: map[string]string{
|
||||
"com.docker.swarm.id": "swarm2-id",
|
||||
"com.docker.swarm.mesos.task": "task2-id",
|
||||
"com.docker.swarm.mesos.name": "con",
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
s := createSlave(t, "test-engine", container1, container2)
|
||||
container3 := &cluster.Container{
|
||||
Container: dockerclient.Container{
|
||||
Id: "container3-id",
|
||||
Names: []string{"/container3-name"},
|
||||
},
|
||||
Config: cluster.BuildContainerConfig(dockerclient.ContainerConfig{}),
|
||||
}
|
||||
|
||||
s := createSlave(t, "test-engine", container1, container2, container3)
|
||||
c.slaves[s.id] = s
|
||||
|
||||
// Hide container without `com.docker.swarm.mesos.task`
|
||||
assert.Equal(t, len(c.Containers()), 2)
|
||||
|
||||
// Invalid lookup
|
||||
assert.Nil(t, c.Container("invalid-id"))
|
||||
assert.Nil(t, c.Container(""))
|
||||
|
|
@ -66,11 +79,6 @@ func TestContainerLookup(t *testing.T) {
|
|||
// Container engine/name matching.
|
||||
assert.NotNil(t, c.Container("test-engine/container1-name1"))
|
||||
assert.NotNil(t, c.Container("test-engine/container1-name2"))
|
||||
// Swarm ID lookup.
|
||||
assert.NotNil(t, c.Container("swarm1-id"))
|
||||
// Swarm ID prefix lookup.
|
||||
assert.NotNil(t, c.Container("swarm1-"))
|
||||
assert.Nil(t, c.Container("swarm"))
|
||||
// Match name before ID prefix
|
||||
cc := c.Container("con")
|
||||
assert.NotNil(t, cc)
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ func TestContainerLookup(t *testing.T) {
|
|||
n := createEngine(t, "test-engine", container1, container2)
|
||||
c.engines[n.ID] = n
|
||||
|
||||
assert.Equal(t, len(c.Containers()), 2)
|
||||
|
||||
// Invalid lookup
|
||||
assert.Nil(t, c.Container("invalid-id"))
|
||||
assert.Nil(t, c.Container(""))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../mesos_helpers
|
||||
|
||||
function teardown() {
|
||||
swarm_manage_cleanup
|
||||
stop_mesos
|
||||
stop_docker
|
||||
}
|
||||
|
||||
@test "mesos - docker ps" {
|
||||
start_docker_with_busybox 2
|
||||
start_mesos
|
||||
swarm_manage --cluster-driver mesos-experimental 127.0.0.1:$MESOS_MASTER_PORT
|
||||
|
||||
# make sure no container exist
|
||||
run docker_swarm ps -qa
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
|
||||
# run
|
||||
docker_swarm run -m 20m -d --name test_container busybox sleep 100
|
||||
|
||||
# verify, container is running
|
||||
run docker_swarm ps -aq
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
|
||||
run docker -H ${HOSTS[0]} run -d --name test_container2 busybox sleep 100
|
||||
|
||||
# verify, container is running
|
||||
run docker -H ${HOSTS[0]} ps -q --filter=name=test_container2 --filter=status=running
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
|
||||
# check we only the swarm containers are displayed
|
||||
run docker_swarm ps -q
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
}
|
||||
Loading…
Reference in New Issue