mirror of https://github.com/k3s-io/k3s
Merge pull request #19393 from yujuhong/fix_dockerclient
Fix fake docker client to corretly report status of containerspull/6/head
commit
651206fd90
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue