@@ -204,7 +204,10 @@ func (p *criStatsProvider) listPodStatsPartiallyFromCRI(ctx context.Context, upd
204
204
}
205
205
206
206
// Fill available stats for full set of required pod stats
207
- cs := p .makeContainerStats (stats , container , rootFsInfo , fsIDtoInfo , podSandbox .GetMetadata (), updateCPUNanoCoreUsage )
207
+ cs , err := p .makeContainerStats (stats , container , rootFsInfo , fsIDtoInfo , podSandbox .GetMetadata (), updateCPUNanoCoreUsage )
208
+ if err != nil {
209
+ return nil , fmt .Errorf ("make container stats: %w" , err )
210
+ }
208
211
p .addPodNetworkStats (ps , podSandboxID , caInfos , cs , containerNetworkStats [podSandboxID ])
209
212
p .addPodCPUMemoryStats (ps , types .UID (podSandbox .Metadata .Uid ), allInfos , cs )
210
213
p .addSwapStats (ps , types .UID (podSandbox .Metadata .Uid ), allInfos , cs )
@@ -249,7 +252,9 @@ func (p *criStatsProvider) listPodStatsStrictlyFromCRI(ctx context.Context, upda
249
252
continue
250
253
}
251
254
ps := buildPodStats (podSandbox )
252
- p .addCRIPodContainerStats (criSandboxStat , ps , fsIDtoInfo , containerMap , podSandbox , rootFsInfo , updateCPUNanoCoreUsage )
255
+ if err := p .addCRIPodContainerStats (criSandboxStat , ps , fsIDtoInfo , containerMap , podSandbox , rootFsInfo , updateCPUNanoCoreUsage ); err != nil {
256
+ return nil , fmt .Errorf ("add CRI pod container stats: %w" , err )
257
+ }
253
258
addCRIPodNetworkStats (ps , criSandboxStat )
254
259
addCRIPodCPUStats (ps , criSandboxStat )
255
260
addCRIPodMemoryStats (ps , criSandboxStat )
@@ -401,7 +406,10 @@ func (p *criStatsProvider) ImageFsStats(ctx context.Context) (*statsapi.FsStats,
401
406
if fs .InodesUsed != nil {
402
407
s .InodesUsed = & fs .InodesUsed .Value
403
408
}
404
- imageFsInfo := p .getFsInfo (fs .GetFsId ())
409
+ imageFsInfo , err := p .getFsInfo (fs .GetFsId ())
410
+ if err != nil {
411
+ return nil , fmt .Errorf ("get filesystem info: %w" , err )
412
+ }
405
413
if imageFsInfo != nil {
406
414
// The image filesystem id is unknown to the local node or there's
407
415
// an error on retrieving the stats. In these cases, we omit those
@@ -423,7 +431,10 @@ func (p *criStatsProvider) ImageFsDevice(ctx context.Context) (string, error) {
423
431
return "" , err
424
432
}
425
433
for _ , fs := range resp {
426
- fsInfo := p .getFsInfo (fs .GetFsId ())
434
+ fsInfo , err := p .getFsInfo (fs .GetFsId ())
435
+ if err != nil {
436
+ return "" , fmt .Errorf ("get filesystem info: %w" , err )
437
+ }
427
438
if fsInfo != nil {
428
439
return fsInfo .Device , nil
429
440
}
@@ -434,10 +445,10 @@ func (p *criStatsProvider) ImageFsDevice(ctx context.Context) (string, error) {
434
445
// getFsInfo returns the information of the filesystem with the specified
435
446
// fsID. If any error occurs, this function logs the error and returns
436
447
// nil.
437
- func (p * criStatsProvider ) getFsInfo (fsID * runtimeapi.FilesystemIdentifier ) * cadvisorapiv2.FsInfo {
448
+ func (p * criStatsProvider ) getFsInfo (fsID * runtimeapi.FilesystemIdentifier ) ( * cadvisorapiv2.FsInfo , error ) {
438
449
if fsID == nil {
439
450
klog .V (2 ).InfoS ("Failed to get filesystem info: fsID is nil" )
440
- return nil
451
+ return nil , nil
441
452
}
442
453
mountpoint := fsID .GetMountpoint ()
443
454
fsInfo , err := p .cadvisor .GetDirFsInfo (mountpoint )
@@ -449,10 +460,11 @@ func (p *criStatsProvider) getFsInfo(fsID *runtimeapi.FilesystemIdentifier) *cad
449
460
klog .V (2 ).InfoS (msg , "mountpoint" , mountpoint , "err" , err )
450
461
} else {
451
462
klog .ErrorS (err , msg , "mountpoint" , mountpoint )
463
+ return nil , fmt .Errorf ("%s: %w" , msg , err )
452
464
}
453
- return nil
465
+ return nil , nil
454
466
}
455
- return & fsInfo
467
+ return & fsInfo , nil
456
468
}
457
469
458
470
// buildPodStats returns a PodStats that identifies the Pod managing cinfo
@@ -590,7 +602,7 @@ func (p *criStatsProvider) makeContainerStats(
590
602
fsIDtoInfo map [runtimeapi.FilesystemIdentifier ]* cadvisorapiv2.FsInfo ,
591
603
meta * runtimeapi.PodSandboxMetadata ,
592
604
updateCPUNanoCoreUsage bool ,
593
- ) * statsapi.ContainerStats {
605
+ ) ( * statsapi.ContainerStats , error ) {
594
606
result := & statsapi.ContainerStats {
595
607
Name : stats .Attributes .Metadata .Name ,
596
608
// The StartTime in the summary API is the container creation time.
@@ -652,10 +664,14 @@ func (p *criStatsProvider) makeContainerStats(
652
664
}
653
665
}
654
666
fsID := stats .GetWritableLayer ().GetFsId ()
667
+ var err error
655
668
if fsID != nil {
656
669
imageFsInfo , found := fsIDtoInfo [* fsID ]
657
670
if ! found {
658
- imageFsInfo = p .getFsInfo (fsID )
671
+ imageFsInfo , err = p .getFsInfo (fsID )
672
+ if err != nil {
673
+ return nil , fmt .Errorf ("get filesystem info: %w" , err )
674
+ }
659
675
fsIDtoInfo [* fsID ] = imageFsInfo
660
676
}
661
677
if imageFsInfo != nil {
@@ -672,12 +688,11 @@ func (p *criStatsProvider) makeContainerStats(
672
688
// NOTE: This doesn't support the old pod log path, `/var/log/pods/UID`. For containers
673
689
// using old log path, empty log stats are returned. This is fine, because we don't
674
690
// officially support in-place upgrade anyway.
675
- var err error
676
691
result .Logs , err = p .hostStatsProvider .getPodContainerLogStats (meta .GetNamespace (), meta .GetName (), types .UID (meta .GetUid ()), container .GetMetadata ().GetName (), rootFsInfo )
677
692
if err != nil {
678
693
klog .ErrorS (err , "Unable to fetch container log stats" , "containerName" , container .GetMetadata ().GetName ())
679
694
}
680
- return result
695
+ return result , nil
681
696
}
682
697
683
698
func (p * criStatsProvider ) makeContainerCPUAndMemoryStats (
0 commit comments