mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 03:33:26 +00:00
Merge pull request #42739 from yujuhong/created_time
Automatic merge from submit-queue (batch tested with PRs 42762, 42739, 42425, 42778) FakeDockerClient: add creation timestamp This fixes #42736
This commit is contained in:
@@ -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) {
|
|||||||
|
|
||||||
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)
|
||||||
|
@@ -54,7 +54,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++ {
|
||||||
@@ -68,7 +68,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 (
|
|||||||
// (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)
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user