pkg/sysinfo: add detection for time-namespaces support

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-04-06 22:37:18 +02:00
parent 9a4a9a4f68
commit c735877246
4 changed files with 21 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ func newV2(options ...Opt) *SysInfo {
applyAppArmorInfo,
applySeccompInfo,
applyCgroupNsInfo,
applyTimeNsInfo,
}
m, err := cgroupsV2.Load(sysInfo.cg2GroupPath)

View File

@@ -21,6 +21,9 @@ type SysInfo struct {
// Whether the kernel supports cgroup namespaces or not
CgroupNamespaces bool
// TimeNamespaces indicates whether the kernel supports time namespaces.
TimeNamespaces bool
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
IPv4ForwardingDisabled bool

View File

@@ -105,6 +105,7 @@ func newV1() *SysInfo {
applyAppArmorInfo,
applySeccompInfo,
applyCgroupNsInfo,
applyTimeNsInfo,
}
sysInfo.cgMounts, err = findCgroupV1Mountpoints()
@@ -283,6 +284,11 @@ func applyCgroupNsInfo(info *SysInfo) {
info.CgroupNamespaces = cgroupnsSupported()
}
// applyTimeNsInfo adds whether time namespaces are supported to the info.
func applyTimeNsInfo(info *SysInfo) {
info.TimeNamespaces = timeNsSupported()
}
// applySeccompInfo checks if Seccomp is supported, via CONFIG_SECCOMP.
func applySeccompInfo(info *SysInfo) {
info.Seccomp = seccomp.IsEnabled()
@@ -306,6 +312,14 @@ func cgroupnsSupported() bool {
return false
}
// timeNsSupported checks whether time namespaces are supported.
func timeNsSupported() bool {
if _, err := os.Stat("/proc/self/ns/time"); !os.IsNotExist(err) {
return true
}
return false
}
func cgroupEnabled(mountPoint, name string) bool {
_, err := os.Stat(path.Join(mountPoint, name))
return err == nil

View File

@@ -64,6 +64,9 @@ func TestNew(t *testing.T) {
if expected := cgroupnsSupported(); sysInfo.CgroupNamespaces != expected {
t.Errorf("got CgroupNamespaces %v, wanted %v", sysInfo.CgroupNamespaces, expected)
}
if expected := timeNsSupported(); sysInfo.TimeNamespaces != expected {
t.Errorf("got TimeNamespaces %v, wanted %v", sysInfo.TimeNamespaces, expected)
}
}
func TestIsCpusetListAvailable(t *testing.T) {