Skip to content

Commit e04f994

Browse files
committed
Fix metrics collection failure in network=host mode
When using hostinet (network=host), /proc/net/dev and /proc/net/snmp may not be available inside the sandbox. Previously Statistics() returned an error when these files were not opened, which propagated up and caused the entire event/metrics collection to fail, breaking kubectl top pod. Return zero-valued stats instead of an error when the proc files are unavailable, as this is expected in hostinet mode. Real errors like parse failures still propagate. Fixes #12723
1 parent 140f64c commit e04f994

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

pkg/sentry/socket/hostinet/stack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ func (s *Stack) Statistics(stat any, arg string) error {
320320
switch stat.(type) {
321321
case *inet.StatDev:
322322
if s.netDevFile == nil {
323-
return fmt.Errorf("/proc/net/dev is not opened for hostinet")
323+
return nil
324324
}
325325
rawLine = getLine(s.netDevFile, arg, false /* with no header */)
326326
case *inet.StatSNMPIP, *inet.StatSNMPICMP, *inet.StatSNMPICMPMSG, *inet.StatSNMPTCP, *inet.StatSNMPUDP, *inet.StatSNMPUDPLite:
327327
if s.netSNMPFile == nil {
328-
return fmt.Errorf("/proc/net/snmp is not opened for hostinet")
328+
return nil
329329
}
330330
rawLine = getLine(s.netSNMPFile, arg, true)
331331
default:

0 commit comments

Comments
 (0)