@@ -77,6 +77,7 @@ const (
77
77
cName5 = "container5-name"
78
78
cName6 = "container6-name"
79
79
cName7 = "container7-name"
80
+ cName8 = "container8-name"
80
81
)
81
82
82
83
func TestCRIListPodStats (t * testing.T ) {
@@ -109,10 +110,14 @@ func TestCRIListPodStats(t *testing.T) {
109
110
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
110
111
containerLogStats4 = makeFakeLogStats (4000 )
111
112
113
+ // Running pod with a terminated container and a running container
112
114
sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" , false )
115
+ sandbox3Cgroup = "/" + cm .GetPodCgroupNameSuffix (types .UID (sandbox2 .PodSandboxStatus .Metadata .Uid ))
113
116
container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
114
117
containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
115
118
containerLogStats5 = makeFakeLogStats (5000 )
119
+ container8 = makeFakeContainer (sandbox3 , cName8 , 0 , false )
120
+ containerStats8 = makeFakeContainerStats (container8 , imageFsMountpoint )
116
121
117
122
// Terminated pod sandbox
118
123
sandbox4 = makeFakePodSandbox ("sandbox1-name" , "sandbox1-uid" , "sandbox1-ns" , true )
@@ -153,6 +158,7 @@ func TestCRIListPodStats(t *testing.T) {
153
158
sandbox2 .PodSandboxStatus .Id : getTestContainerInfo (seedSandbox2 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , leaky .PodInfraContainerName ),
154
159
sandbox2Cgroup : getTestContainerInfo (seedSandbox2 , "" , "" , "" ),
155
160
container4 .ContainerStatus .Id : getTestContainerInfo (seedContainer3 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , cName3 ),
161
+ sandbox3Cgroup : getTestContainerInfo (seedSandbox3 , "" , "" , "" ),
156
162
}
157
163
158
164
options := cadvisorapiv2.RequestOptions {
@@ -170,10 +176,10 @@ func TestCRIListPodStats(t *testing.T) {
170
176
sandbox0 , sandbox1 , sandbox2 , sandbox3 , sandbox4 , sandbox5 ,
171
177
})
172
178
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
173
- container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 ,
179
+ container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 , container8 ,
174
180
})
175
181
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
176
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 ,
182
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 , containerStats8
177
183
})
178
184
179
185
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -296,14 +302,12 @@ func TestCRIListPodStats(t *testing.T) {
296
302
assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
297
303
assert .Equal (1 , len (p3 .Containers ))
298
304
299
- c5 := p3 .Containers [0 ]
300
- assert .Equal (cName5 , c5 .Name )
301
- assert .Equal (container5 .CreatedAt , c5 .StartTime .UnixNano ())
302
- assert .NotNil (c5 .CPU .Time )
303
- assert .Zero (* c5 .CPU .UsageCoreNanoSeconds )
304
- assert .Zero (* c5 .CPU .UsageNanoCores )
305
- assert .NotNil (c5 .Memory .Time )
306
- assert .Zero (* c5 .Memory .WorkingSetBytes )
305
+ c8 := p3 .Containers [0 ]
306
+ assert .Equal (cName8 , c8 .Name )
307
+ assert .Equal (container8 .CreatedAt , c8 .StartTime .UnixNano ())
308
+ assert .NotNil (c8 .CPU .Time )
309
+ assert .NotNil (c8 .Memory .Time )
310
+ checkCRIPodCPUAndMemoryStats (assert , p3 , infos [sandbox3Cgroup ].Stats [0 ])
307
311
308
312
mockCadvisor .AssertExpectations (t )
309
313
}
@@ -333,9 +337,13 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
333
337
container4 = makeFakeContainer (sandbox2 , cName3 , 1 , false )
334
338
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
335
339
340
+ // Running pod with a terminated container and a running container
336
341
sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" , false )
342
+ sandbox3Cgroup = "/" + cm .GetPodCgroupNameSuffix (types .UID (sandbox2 .PodSandboxStatus .Metadata .Uid ))
337
343
container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
338
344
containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
345
+ container8 = makeFakeContainer (sandbox3 , cName8 , 0 , false )
346
+ containerStats8 = makeFakeContainerStats (container8 , imageFsMountpoint )
339
347
340
348
// Terminated pod sandbox
341
349
sandbox4 = makeFakePodSandbox ("sandbox1-name" , "sandbox1-uid" , "sandbox1-ns" , true )
@@ -370,6 +378,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
370
378
sandbox2 .PodSandboxStatus .Id : getTestContainerInfo (seedSandbox2 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , leaky .PodInfraContainerName ),
371
379
sandbox2Cgroup : getTestContainerInfo (seedSandbox2 , "" , "" , "" ),
372
380
container4 .ContainerStatus .Id : getTestContainerInfo (seedContainer3 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , cName3 ),
381
+ sandbox3Cgroup : getTestContainerInfo (seedSandbox3 , "" , "" , "" ),
373
382
}
374
383
375
384
options := cadvisorapiv2.RequestOptions {
@@ -384,10 +393,10 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
384
393
sandbox0 , sandbox1 , sandbox2 , sandbox3 , sandbox4 , sandbox5 ,
385
394
})
386
395
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
387
- container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 ,
396
+ container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 , container8 ,
388
397
})
389
398
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
390
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 ,
399
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 , containerStats8 ,
391
400
})
392
401
393
402
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -484,14 +493,12 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
484
493
assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
485
494
assert .Equal (1 , len (p3 .Containers ))
486
495
487
- c5 := p3 .Containers [0 ]
488
- assert .Equal (cName5 , c5 .Name )
489
- assert .Equal (container5 .CreatedAt , c5 .StartTime .UnixNano ())
490
- assert .NotNil (c5 .CPU .Time )
491
- assert .Zero (* c5 .CPU .UsageCoreNanoSeconds )
492
- assert .Zero (* c5 .CPU .UsageNanoCores )
493
- assert .NotNil (c5 .Memory .Time )
494
- assert .Zero (* c5 .Memory .WorkingSetBytes )
496
+ c8 := p3 .Containers [0 ]
497
+ assert .Equal (cName8 , c8 .Name )
498
+ assert .Equal (container8 .CreatedAt , c8 .StartTime .UnixNano ())
499
+ assert .NotNil (c8 .CPU .Time )
500
+ assert .NotNil (c8 .Memory .Time )
501
+ checkCRIPodCPUAndMemoryStats (assert , p3 , infos [sandbox3Cgroup ].Stats [0 ])
495
502
496
503
mockCadvisor .AssertExpectations (t )
497
504
}
0 commit comments