Merge pull request #98 from brendandburns/container_info

Only manage containers with '--' in the name.  Addresses #4
pull/6/head
Daniel Smith 2014-06-13 12:24:49 -07:00
commit 6d4e1632b3
2 changed files with 15 additions and 2 deletions

View File

@ -572,6 +572,11 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
existingContainers, _ := kl.ListContainers()
log.Printf("Existing:\n%#v Desired: %#v", existingContainers, desired)
for _, container := range existingContainers {
// This is slightly hacky, but we ignore containers that lack '--' in their name
// to allow users to manually spin up their own containers if they want.
if !strings.Contains(container, "--") {
continue
}
if !desired[container] {
log.Printf("Killing: %s", container)
err = kl.KillContainer(container)

View File

@ -91,6 +91,7 @@ type FakeDockerClient struct {
container *docker.Container
err error
called []string
stopped string
}
func (f *FakeDockerClient) clearCalls() {
@ -123,6 +124,7 @@ func (f *FakeDockerClient) StartContainer(id string, hostConfig *docker.HostConf
func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
f.appendCall("stop")
f.stopped = id
return nil
}
@ -528,9 +530,14 @@ func TestSyncManifestsDeletes(t *testing.T) {
}
fakeDocker.containerList = []docker.APIContainers{
{
Names: []string{"foo"},
// the '--' is required for the kubelet to manage the container
Names: []string{"foo--bar"},
ID: "1234",
},
{
Names: []string{"foo"},
ID: "4567",
},
}
kubelet := Kubelet{
DockerClient: &fakeDocker,
@ -540,7 +547,8 @@ func TestSyncManifestsDeletes(t *testing.T) {
if len(fakeDocker.called) != 3 ||
fakeDocker.called[0] != "list" ||
fakeDocker.called[1] != "list" ||
fakeDocker.called[2] != "stop" {
fakeDocker.called[2] != "stop" ||
fakeDocker.stopped != "1234" {
t.Errorf("Unexpected call sequence: %#v", fakeDocker.called)
}
}