@@ -57,19 +57,23 @@ const (
57
57
seedContainer2 = 5000
58
58
seedSandbox2 = 6000
59
59
seedContainer3 = 7000
60
+ seedSandbox3 = 8000
61
+ seedContainer5 = 9000
60
62
)
61
63
62
64
const (
63
65
pName0 = "pod0"
64
66
pName1 = "pod1"
65
67
pName2 = "pod2"
68
+ pName3 = "pod3"
66
69
)
67
70
68
71
const (
69
72
cName0 = "container0-name"
70
73
cName1 = "container1-name"
71
74
cName2 = "container2-name"
72
75
cName3 = "container3-name"
76
+ cName5 = "container5-name"
73
77
)
74
78
75
79
func TestCRIListPodStats (t * testing.T ) {
@@ -101,6 +105,11 @@ func TestCRIListPodStats(t *testing.T) {
101
105
container4 = makeFakeContainer (sandbox2 , cName3 , 1 , false )
102
106
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
103
107
containerLogStats4 = makeFakeLogStats (4000 )
108
+
109
+ sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" )
110
+ container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
111
+ containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
112
+ containerLogStats5 = makeFakeLogStats (5000 )
104
113
)
105
114
106
115
var (
@@ -140,13 +149,13 @@ func TestCRIListPodStats(t *testing.T) {
140
149
On ("GetDirFsInfo" , imageFsMountpoint ).Return (imageFsInfo , nil ).
141
150
On ("GetDirFsInfo" , unknownMountpoint ).Return (cadvisorapiv2.FsInfo {}, cadvisorfs .ErrNoSuchDevice )
142
151
fakeRuntimeService .SetFakeSandboxes ([]* critest.FakePodSandbox {
143
- sandbox0 , sandbox1 , sandbox2 ,
152
+ sandbox0 , sandbox1 , sandbox2 , sandbox3 ,
144
153
})
145
154
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
146
- container0 , container1 , container2 , container3 , container4 ,
155
+ container0 , container1 , container2 , container3 , container4 , container5 ,
147
156
})
148
157
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
149
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 ,
158
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 ,
150
159
})
151
160
152
161
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -161,6 +170,7 @@ func TestCRIListPodStats(t *testing.T) {
161
170
kuberuntime .BuildContainerLogsDirectory (types .UID ("sandbox0-uid" ), cName1 ): containerLogStats1 ,
162
171
kuberuntime .BuildContainerLogsDirectory (types .UID ("sandbox1-uid" ), cName2 ): containerLogStats2 ,
163
172
kuberuntime .BuildContainerLogsDirectory (types .UID ("sandbox2-uid" ), cName3 ): containerLogStats4 ,
173
+ kuberuntime .BuildContainerLogsDirectory (types .UID ("sandbox3-uid" ), cName5 ): containerLogStats5 ,
164
174
}
165
175
fakeLogStatsProvider := NewFakeLogMetricsService (fakeLogStats )
166
176
@@ -177,7 +187,7 @@ func TestCRIListPodStats(t *testing.T) {
177
187
stats , err := provider .ListPodStats ()
178
188
assert := assert .New (t )
179
189
assert .NoError (err )
180
- assert .Equal (3 , len (stats ))
190
+ assert .Equal (4 , len (stats ))
181
191
182
192
podStatsMap := make (map [statsapi.PodReference ]statsapi.PodStats )
183
193
for _ , s := range stats {
@@ -239,6 +249,19 @@ func TestCRIListPodStats(t *testing.T) {
239
249
checkCRINetworkStats (assert , p2 .Network , infos [sandbox2 .PodSandboxStatus .Id ].Stats [0 ].Network )
240
250
checkCRIPodCPUAndMemoryStats (assert , p2 , infos [sandbox2Cgroup ].Stats [0 ])
241
251
252
+ p3 := podStatsMap [statsapi.PodReference {Name : "sandbox3-name" , UID : "sandbox3-uid" , Namespace : "sandbox3-ns" }]
253
+ assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
254
+ assert .Equal (1 , len (p3 .Containers ))
255
+
256
+ c5 := p3 .Containers [0 ]
257
+ assert .Equal (cName5 , c5 .Name )
258
+ assert .Equal (container5 .CreatedAt , c5 .StartTime .UnixNano ())
259
+ assert .NotNil (c5 .CPU .Time )
260
+ assert .Zero (* c5 .CPU .UsageCoreNanoSeconds )
261
+ assert .Zero (* c5 .CPU .UsageNanoCores )
262
+ assert .NotNil (c5 .Memory .Time )
263
+ assert .Zero (* c5 .Memory .WorkingSetBytes )
264
+
242
265
mockCadvisor .AssertExpectations (t )
243
266
}
244
267
@@ -266,6 +289,10 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
266
289
containerStats3 = makeFakeContainerStats (container3 , imageFsMountpoint )
267
290
container4 = makeFakeContainer (sandbox2 , cName3 , 1 , false )
268
291
containerStats4 = makeFakeContainerStats (container4 , imageFsMountpoint )
292
+
293
+ sandbox3 = makeFakePodSandbox ("sandbox3-name" , "sandbox3-uid" , "sandbox3-ns" )
294
+ container5 = makeFakeContainer (sandbox3 , cName5 , 0 , true )
295
+ containerStats5 = makeFakeContainerStats (container5 , imageFsMountpoint )
269
296
)
270
297
271
298
var (
@@ -301,13 +328,13 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
301
328
mockCadvisor .
302
329
On ("ContainerInfoV2" , "/" , options ).Return (infos , nil )
303
330
fakeRuntimeService .SetFakeSandboxes ([]* critest.FakePodSandbox {
304
- sandbox0 , sandbox1 , sandbox2 ,
331
+ sandbox0 , sandbox1 , sandbox2 , sandbox3 ,
305
332
})
306
333
fakeRuntimeService .SetFakeContainers ([]* critest.FakeContainer {
307
- container0 , container1 , container2 , container3 , container4 ,
334
+ container0 , container1 , container2 , container3 , container4 , container5 ,
308
335
})
309
336
fakeRuntimeService .SetFakeContainerStats ([]* runtimeapi.ContainerStats {
310
- containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 ,
337
+ containerStats0 , containerStats1 , containerStats2 , containerStats3 , containerStats4 , containerStats5 ,
311
338
})
312
339
313
340
ephemeralVolumes := makeFakeVolumeStats ([]string {"ephVolume1, ephVolumes2" })
@@ -330,7 +357,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
330
357
stats , err := provider .ListPodCPUAndMemoryStats ()
331
358
assert := assert .New (t )
332
359
assert .NoError (err )
333
- assert .Equal (3 , len (stats ))
360
+ assert .Equal (4 , len (stats ))
334
361
335
362
podStatsMap := make (map [statsapi.PodReference ]statsapi.PodStats )
336
363
for _ , s := range stats {
@@ -399,6 +426,19 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
399
426
assert .Nil (c2 .Accelerators )
400
427
assert .Nil (c2 .UserDefinedMetrics )
401
428
429
+ p3 := podStatsMap [statsapi.PodReference {Name : "sandbox3-name" , UID : "sandbox3-uid" , Namespace : "sandbox3-ns" }]
430
+ assert .Equal (sandbox3 .CreatedAt , p3 .StartTime .UnixNano ())
431
+ assert .Equal (1 , len (p3 .Containers ))
432
+
433
+ c5 := p3 .Containers [0 ]
434
+ assert .Equal (cName5 , c5 .Name )
435
+ assert .Equal (container5 .CreatedAt , c5 .StartTime .UnixNano ())
436
+ assert .NotNil (c5 .CPU .Time )
437
+ assert .Zero (* c5 .CPU .UsageCoreNanoSeconds )
438
+ assert .Zero (* c5 .CPU .UsageNanoCores )
439
+ assert .NotNil (c5 .Memory .Time )
440
+ assert .Zero (* c5 .Memory .WorkingSetBytes )
441
+
402
442
mockCadvisor .AssertExpectations (t )
403
443
}
404
444
0 commit comments