Commit 38d8da12 authored by Yu-Ju Hong's avatar Yu-Ju Hong

FakeDockerClient: add creation timestamp

This is necessary for kubemark to work correctly.
parent d6ae61c3
...@@ -47,7 +47,7 @@ func makeContainerConfig(sConfig *runtimeapi.PodSandboxConfig, name, image strin ...@@ -47,7 +47,7 @@ func makeContainerConfig(sConfig *runtimeapi.PodSandboxConfig, name, image strin
// TestListContainers creates several containers and then list them to check // TestListContainers creates several containers and then list them to check
// whether the correct metadatas, states, and labels are returned. // whether the correct metadatas, states, and labels are returned.
func TestListContainers(t *testing.T) { func TestListContainers(t *testing.T) {
ds, _, _ := newTestDockerService() ds, _, fakeClock := newTestDockerService()
podName, namespace := "foo", "bar" podName, namespace := "foo", "bar"
containerName, image := "sidecar", "logger" containerName, image := "sidecar", "logger"
...@@ -66,7 +66,7 @@ func TestListContainers(t *testing.T) { ...@@ -66,7 +66,7 @@ func TestListContainers(t *testing.T) {
expected := []*runtimeapi.Container{} expected := []*runtimeapi.Container{}
state := runtimeapi.ContainerState_CONTAINER_RUNNING state := runtimeapi.ContainerState_CONTAINER_RUNNING
var createdAt int64 = 0 var createdAt int64 = fakeClock.Now().UnixNano()
for i := range configs { for i := range configs {
// We don't care about the sandbox id; pass a bogus one. // We don't care about the sandbox id; pass a bogus one.
sandboxID := fmt.Sprintf("sandboxid%d", i) sandboxID := fmt.Sprintf("sandboxid%d", i)
......
...@@ -52,7 +52,7 @@ func makeSandboxConfigWithLabelsAndAnnotations(name, namespace, uid string, atte ...@@ -52,7 +52,7 @@ func makeSandboxConfigWithLabelsAndAnnotations(name, namespace, uid string, atte
// TestListSandboxes creates several sandboxes and then list them to check // TestListSandboxes creates several sandboxes and then list them to check
// whether the correct metadatas, states, and labels are returned. // whether the correct metadatas, states, and labels are returned.
func TestListSandboxes(t *testing.T) { func TestListSandboxes(t *testing.T) {
ds, _, _ := newTestDockerService() ds, _, fakeClock := newTestDockerService()
name, namespace := "foo", "bar" name, namespace := "foo", "bar"
configs := []*runtimeapi.PodSandboxConfig{} configs := []*runtimeapi.PodSandboxConfig{}
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
...@@ -66,7 +66,7 @@ func TestListSandboxes(t *testing.T) { ...@@ -66,7 +66,7 @@ func TestListSandboxes(t *testing.T) {
expected := []*runtimeapi.PodSandbox{} expected := []*runtimeapi.PodSandbox{}
state := runtimeapi.PodSandboxState_SANDBOX_READY state := runtimeapi.PodSandboxState_SANDBOX_READY
var createdAt int64 = 0 var createdAt int64 = fakeClock.Now().UnixNano()
for i := range configs { for i := range configs {
id, err := ds.RunPodSandbox(configs[i]) id, err := ds.RunPodSandbox(configs[i])
assert.NoError(t, err) assert.NoError(t, err)
......
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
// (kubecontainer) types. // (kubecontainer) types.
const ( const (
statusRunningPrefix = "Up" statusRunningPrefix = "Up"
statusCreatedPrefix = "Created"
statusExitedPrefix = "Exited" statusExitedPrefix = "Exited"
) )
......
...@@ -516,12 +516,13 @@ func (f *FakeDockerClient) CreateContainer(c dockertypes.ContainerCreateConfig) ...@@ -516,12 +516,13 @@ func (f *FakeDockerClient) CreateContainer(c dockertypes.ContainerCreateConfig)
name := "/" + c.Name name := "/" + c.Name
id := GetFakeContainerID(name) id := GetFakeContainerID(name)
f.appendContainerTrace("Created", id) f.appendContainerTrace("Created", id)
timestamp := f.Clock.Now()
// The newest container should be in front, because we assume so in GetPodStatus() // The newest container should be in front, because we assume so in GetPodStatus()
f.RunningContainerList = append([]dockertypes.Container{ f.RunningContainerList = append([]dockertypes.Container{
{ID: id, Names: []string{name}, Image: c.Config.Image, Labels: c.Config.Labels}, {ID: id, Names: []string{name}, Image: c.Config.Image, Created: timestamp.Unix(), State: statusCreatedPrefix, Labels: c.Config.Labels},
}, f.RunningContainerList...) }, f.RunningContainerList...)
f.ContainerMap[id] = convertFakeContainer(&FakeContainer{ f.ContainerMap[id] = convertFakeContainer(&FakeContainer{
ID: id, Name: name, Config: c.Config, HostConfig: c.HostConfig, CreatedAt: f.Clock.Now()}) ID: id, Name: name, Config: c.Config, HostConfig: c.HostConfig, CreatedAt: timestamp})
f.normalSleep(100, 25, 25) f.normalSleep(100, 25, 25)
...@@ -539,12 +540,13 @@ func (f *FakeDockerClient) StartContainer(id string) error { ...@@ -539,12 +540,13 @@ func (f *FakeDockerClient) StartContainer(id string) error {
} }
f.appendContainerTrace("Started", id) f.appendContainerTrace("Started", id)
container, ok := f.ContainerMap[id] container, ok := f.ContainerMap[id]
timestamp := f.Clock.Now()
if !ok { if !ok {
container = convertFakeContainer(&FakeContainer{ID: id, Name: id}) container = convertFakeContainer(&FakeContainer{ID: id, Name: id, CreatedAt: timestamp})
} }
container.State.Running = true container.State.Running = true
container.State.Pid = os.Getpid() container.State.Pid = os.Getpid()
container.State.StartedAt = dockerTimestampToString(f.Clock.Now()) container.State.StartedAt = dockerTimestampToString(timestamp)
container.NetworkSettings.IPAddress = "2.3.4.5" container.NetworkSettings.IPAddress = "2.3.4.5"
f.ContainerMap[id] = container f.ContainerMap[id] = container
f.updateContainerStatus(id, statusRunningPrefix) f.updateContainerStatus(id, statusRunningPrefix)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment