diff --git a/container/common/helpers.go b/container/common/helpers.go index a8d8e4379b8..a2422e5cc1b 100644 --- a/container/common/helpers.go +++ b/container/common/helpers.go @@ -30,6 +30,7 @@ import ( "github.com/karrick/godirwalk" "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/pkg/errors" + "golang.org/x/sys/unix" "k8s.io/klog/v2" ) @@ -97,6 +98,14 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF lowestTime = fi.ModTime() } } + var info unix.Sysinfo_t + if err := unix.Sysinfo(&info); err == nil { + sinceBoot := time.Duration(info.Uptime) * time.Second + // If time is before boot, use boot time instead + if now.Sub(lowestTime) > sinceBoot { + lowestTime = now.Add(-1 * sinceBoot) + } + } if lowestTime != now { spec.CreationTime = lowestTime