Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fake docker client to corretly report status of containers #19393

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/kubelet/dockertools/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import (

// This file contains helper functions to convert docker API types to runtime
// (kubecontainer) types.
const (
statusRunningPrefix = "Up"
statusExitedPrefix = "Exited"
)

func mapState(state string) kubecontainer.ContainerState {
// Parse the state string in docker.APIContainers. This could break when
// we upgrade docker.
switch {
case strings.HasPrefix(state, "Up"):
case strings.HasPrefix(state, statusRunningPrefix):
return kubecontainer.ContainerStateRunning
case strings.HasPrefix(state, "Exited"):
case strings.HasPrefix(state, statusExitedPrefix):
return kubecontainer.ContainerStateExited
default:
return kubecontainer.ContainerStateUnknown
Expand Down
10 changes: 10 additions & 0 deletions pkg/kubelet/dockertools/fake_docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (f *FakeDockerClient) StartContainer(id string, hostConfig *docker.HostConf
}
container.NetworkSettings = &docker.NetworkSettings{IPAddress: "2.3.4.5"}
f.ContainerMap[id] = container
f.updateContainerStatus(id, statusRunningPrefix)
f.normalSleep(200, 50, 50)
return nil
}
Expand Down Expand Up @@ -322,6 +323,7 @@ func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
container.State.Running = false
}
f.ContainerMap[id] = container
f.updateContainerStatus(id, statusExitedPrefix)
f.normalSleep(200, 50, 50)
return nil
}
Expand Down Expand Up @@ -412,6 +414,14 @@ func (f *FakeDockerClient) RemoveImage(image string) error {
return err
}

func (f *FakeDockerClient) updateContainerStatus(id, status string) {
for i := range f.ContainerList {
if f.ContainerList[i].ID == id {
f.ContainerList[i].Status = status
}
}
}

// FakeDockerPuller is a stub implementation of DockerPuller.
type FakeDockerPuller struct {
sync.Mutex
Expand Down