display only containers created by swarm in mesos

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-08-10 16:00:38 -07:00
parent d580bf9b7b
commit 2a70ff3e1f
3 changed files with 43 additions and 8 deletions

View File

@ -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))
}
}
}
}

View File

@ -32,7 +32,7 @@ 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",
},
}),
}
@ -44,7 +44,7 @@ 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",
},
}),
}
@ -66,11 +66,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)

View File

@ -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 ]
}