@@ -61,6 +61,7 @@ const (
61
61
seedContainer2 = 5000
62
62
seedSandbox2 = 6000
63
63
seedContainer3 = 7000
64
+ seedSandbox3 = 8000
64
65
)
65
66
66
67
const (
@@ -77,6 +78,7 @@ const (
77
78
cName5 = "container5-name"
78
79
cName6 = "container6-name"
79
80
cName7 = "container7-name"
81
+ cName8 = "container8-name"
80
82
)
81
83
82
84
func TestCRIListPodStats (t * testing.T ) {
@@ -109,10 +111,15 @@ func TestCRIListPodStats(t *testing.T) {
109
111
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
110
112
containerLogStats4 = makeFakeLogStats (4000 )
111
113
114
+ // Running pod with a terminated container and a running container
112
115
sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" , false )
116
+ sandbox3Cgroup = "/" + cm .GetPodCgroupNameSuffix (types .UID (sandbox3 .PodSandboxStatus .Metadata .Uid ))
113
117
container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
114
118
containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
115
119
containerLogStats5 = makeFakeLogStats (5000 )
120
+ container8 = makeFakeContainer (sandbox3 , cName8 , 0 , false )
121
+ containerStats8 = makeFakeContainerStats (container8 , imageFsMountpoint )
122
+ containerLogStats8 = makeFakeLogStats (6000 )
116
123
117
124
// Terminated pod sandbox
118
125
sandbox4 = makeFakePodSandbox ("sandbox1-name" , "sandbox1-uid" , "sandbox1-ns" , true )
@@ -153,6 +160,7 @@ func TestCRIListPodStats(t *testing.T) {
153
160
sandbox2 .PodSandboxStatus .Id : getTestContainerInfo (seedSandbox2 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , leaky .PodInfraContainerName ),
154
161
sandbox2Cgroup : getTestContainerInfo (seedSandbox2 , "" , "" , "" ),
155
162
container4 .ContainerStatus .Id : getTestContainerInfo (seedContainer3 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , cName3 ),
163
+ sandbox3Cgroup : getTestContainerInfo (seedSandbox3 , "" , "" , "" ),
156
164
}
157
165
158
166
options := cadvisorapiv2.RequestOptions {
@@ -170,10 +178,10 @@ func TestCRIListPodStats(t *testing.T) {
170
178
sandbox0 , sandbox1 , sandbox2 , sandbox3 , sandbox4 , sandbox5 ,
171
179
})
172
180
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
173
- container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 ,
181
+ container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 , container8 ,
174
182
})
175
183
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
176
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 ,
184
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 , containerStats8 ,
177
185
})
178
186
179
187
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -189,6 +197,7 @@ func TestCRIListPodStats(t *testing.T) {
189
197
kuberuntime .BuildContainerLogsDirectory ("sandbox1-ns" , "sandbox1-name" , types .UID ("sandbox1-uid" ), cName2 ): containerLogStats2 ,
190
198
kuberuntime .BuildContainerLogsDirectory ("sandbox2-ns" , "sandbox2-name" , types .UID ("sandbox2-uid" ), cName3 ): containerLogStats4 ,
191
199
kuberuntime .BuildContainerLogsDirectory ("sandbox3-ns" , "sandbox3-name" , types .UID ("sandbox3-uid" ), cName5 ): containerLogStats5 ,
200
+ kuberuntime .BuildContainerLogsDirectory ("sandbox3-ns" , "sandbox3-name" , types .UID ("sandbox3-uid" ), cName8 ): containerLogStats8 ,
192
201
filepath .Join (kuberuntime .BuildPodLogsDirectory ("sandbox0-ns" , "sandbox0-name" , types .UID ("sandbox0-uid" )), podLogName0 ): podLogStats0 ,
193
202
filepath .Join (kuberuntime .BuildPodLogsDirectory ("sandbox1-ns" , "sandbox1-name" , types .UID ("sandbox1-uid" )), podLogName1 ): podLogStats1 ,
194
203
}
@@ -296,14 +305,12 @@ func TestCRIListPodStats(t *testing.T) {
296
305
assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
297
306
assert .Equal (1 , len (p3 .Containers ))
298
307
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 )
308
+ c8 := p3 .Containers [0 ]
309
+ assert .Equal (cName8 , c8 .Name )
310
+ assert .Equal (container8 .CreatedAt , c8 .StartTime .UnixNano ())
311
+ assert .NotNil (c8 .CPU .Time )
312
+ assert .NotNil (c8 .Memory .Time )
313
+ checkCRIPodCPUAndMemoryStats (assert , p3 , infos [sandbox3Cgroup ].Stats [0 ])
307
314
308
315
mockCadvisor .AssertExpectations (t )
309
316
}
@@ -333,9 +340,13 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
333
340
container4 = makeFakeContainer (sandbox2 , cName3 , 1 , false )
334
341
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
335
342
343
+ // Running pod with a terminated container and a running container
336
344
sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" , false )
345
+ sandbox3Cgroup = "/" + cm .GetPodCgroupNameSuffix (types .UID (sandbox3 .PodSandboxStatus .Metadata .Uid ))
337
346
container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
338
347
containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
348
+ container8 = makeFakeContainer (sandbox3 , cName8 , 0 , false )
349
+ containerStats8 = makeFakeContainerStats (container8 , imageFsMountpoint )
339
350
340
351
// Terminated pod sandbox
341
352
sandbox4 = makeFakePodSandbox ("sandbox1-name" , "sandbox1-uid" , "sandbox1-ns" , true )
@@ -370,6 +381,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
370
381
sandbox2 .PodSandboxStatus .Id : getTestContainerInfo (seedSandbox2 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , leaky .PodInfraContainerName ),
371
382
sandbox2Cgroup : getTestContainerInfo (seedSandbox2 , "" , "" , "" ),
372
383
container4 .ContainerStatus .Id : getTestContainerInfo (seedContainer3 , pName2 , sandbox2 .PodSandboxStatus .Metadata .Namespace , cName3 ),
384
+ sandbox3Cgroup : getTestContainerInfo (seedSandbox3 , "" , "" , "" ),
373
385
}
374
386
375
387
options := cadvisorapiv2.RequestOptions {
@@ -384,10 +396,10 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
384
396
sandbox0 , sandbox1 , sandbox2 , sandbox3 , sandbox4 , sandbox5 ,
385
397
})
386
398
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
387
- container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 ,
399
+ container0 , container1 , container2 , container3 , container4 , container5 , container6 , container7 , container8 ,
388
400
})
389
401
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
390
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 ,
402
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 , containerStats6 , containerStats7 , containerStats8 ,
391
403
})
392
404
393
405
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -484,14 +496,12 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
484
496
assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
485
497
assert .Equal (1 , len (p3 .Containers ))
486
498
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 )
499
+ c8 := p3 .Containers [0 ]
500
+ assert .Equal (cName8 , c8 .Name )
501
+ assert .Equal (container8 .CreatedAt , c8 .StartTime .UnixNano ())
502
+ assert .NotNil (c8 .CPU .Time )
503
+ assert .NotNil (c8 .Memory .Time )
504
+ checkCRIPodCPUAndMemoryStats (assert , p3 , infos [sandbox3Cgroup ].Stats [0 ])
495
505
496
506
mockCadvisor .AssertExpectations (t )
497
507
}
0 commit comments