Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: CPU.Time is set to cs.StartTime but ps.Memory.Time is set to timestamp when collecting the memoryusage. What you expected to happen: CPU.Time is set to cs.CPU.Time How to reproduce it (as minimally and precisely as possible): Check the code Anything else we need to know?: Environment: Kubernetes version (use ): master branch when creating this issue. Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
/assign
/sig kubelet
The label(s) cannot be applied, because the repository doesn't have them <detailsIn response to : /sig kubelet Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig node
I am happy to take over this. /assign

Discussion:
ps.CPU = &statsapi.CPUStats{} } <del> ps.CPU.Time = cs.StartTime </del> <ins> ps.CPU.Time = cs.CPU.Time </ins> usageCoreNanoSeconds := getUint64Value(cs.CPU.UsageCoreNanoSeconds) + getUint64Value(ps.CPU.UsageCoreNanoSeconds) usageNanoCores := getUint64Value(cs.CPU.UsageNanoCores) + getUint64Value(ps.CPU.UsageNanoCores) ps.CPU.UsageCoreNanoSeconds = &usageCoreNanoSeconds

cName6 = "container6-name" cName7 = "container7-name" cName8 = "container8-name" <ins> cName9 = "container9-name" </ins> ) func TestCRIListPodStats(t *testing.T) {

sandbox5        = makeFakePodSandbox("sandbox1-name", "sandbox5-uid", "sandbox1-ns", true) container7      = makeFakeContainer(sandbox5, cName7, 0, true) containerStats7 = makeFakeContainerStats(container7, imageFsMountpoint) <ins> // A pod that cadvisor returns no stats sandbox6        = makeFakePodSandbox("sandbox6-name", "sandbox6-uid", "sandbox6-ns", false) container9      = makeFakeContainer(sandbox6, cName9, 0, false) containerStats9 = makeFakeContainerStats(container9, imageFsMountpoint) </ins> ) var (

mockCadvisor. On("ContainerInfoV2", "/", options).Return(infos, nil) fakeRuntimeService.SetFakeSandboxes([]*critest.FakePodSandbox{ <del> sandbox0, sandbox1, sandbox2, sandbox3, sandbox4, sandbox5, </del> <ins> sandbox0, sandbox1, sandbox2, sandbox3, sandbox4, sandbox5, sandbox6, </ins> }) fakeRuntimeService.SetFakeContainers([]*critest.FakeContainer{ <del> container0, container1, container2, container3, container4, container5, container6, container7, container8, </del> <ins> container0, container1, container2, container3, container4, container5, container6, container7, container8, container9, </ins> }) fakeRuntimeService.SetFakeContainerStats([]*runtimeapi.ContainerStats{ <del> containerStats0, containerStats1, containerStats2, containerStats3, containerStats4, containerStats5, containerStats6, containerStats7, containerStats8, </del> <ins> containerStats0, containerStats1, containerStats2, containerStats3, containerStats4, containerStats5, containerStats6, containerStats7, containerStats8, containerStats9, </ins> }) ephemeralVolumes := makeFakeVolumeStats([]string{"ephVolume1, ephVolumes2"})

stats, err := provider.ListPodCPUAndMemoryStats() assert := assert.New(t) assert.NoError(err) <del> assert.Equal(4, len(stats)) </del> <ins> assert.Equal(5, len(stats)) </ins> podStatsMap := make(map[statsapi.PodReference]statsapi.PodStats) for _, s := range stats {

assert.NotNil(c8.Memory.Time) checkCRIPodCPUAndMemoryStats(assert, p3, infos[sandbox3Cgroup].Stats[0]) <ins> p6 := podStatsMap[statsapi.PodReference{Name: "sandbox6-name", UID: "sandbox6-uid", Namespace: "sandbox6-ns"}] assert.Equal(sandbox6.CreatedAt, p6.StartTime.UnixNano()) assert.Equal(1, len(p6.Containers)) c9 := p6.Containers[0] assert.Equal(cName9, c9.Name) assert.Equal(container9.CreatedAt, c9.StartTime.UnixNano()) assert.NotNil(c9.CPU.Time) assert.Equal(containerStats9.Cpu.Timestamp, p6.CPU.Time.UnixNano()) assert.NotNil(c9.Memory.Time) assert.Equal(containerStats9.Memory.Timestamp, p6.Memory.Time.UnixNano()) </ins> mockCadvisor.AssertExpectations(t) }