From 224e60cef28eee185e2429d6392533fbec016abf Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Fri, 2 Apr 2021 00:08:58 -0700 Subject: [PATCH] hostifo: update LXC, add Cloud Run. Recent LXC support no longer has "lxc" in /proc/1/cgroup: # cat /proc/1/cgroup 12:freezer:/ 11:rdma:/ 10:cpuset:/ 9:pids:/ 8:blkio:/ 7:devices:/ 6:perf_event:/ 5:net_cls,net_prio:/ 4:memory:/ 3:hugetlb:/ 2:cpu,cpuacct:/ 1:name=systemd:/init.scope 0::/init.scope Look for fuse.lxcfs in /proc.mounts in addition: # grep lxc /proc/mounts lxcfs /proc/cpuinfo fuse.lxcfs ... lxcfs /proc/diskstats fuse.lxcfs ... lxcfs /proc/loadavg fuse.lxcfs ... lxcfs /proc/meminfo fuse.lxcfs ... lxcfs /proc/stat fuse.lxcfs ... lxcfs /proc/swaps fuse.lxcfs ... lxcfs /proc/uptime fuse.lxcfs ... lxcfs /sys/devices/system/cpu/online fuse.lxcfs ... Add Knative detection by looking for the environment variables which are part of its container contract. Signed-off-by: Denton Gentry --- control/controlclient/hostinfo_linux.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/control/controlclient/hostinfo_linux.go b/control/controlclient/hostinfo_linux.go index 0fd125a87..e79eaaa89 100644 --- a/control/controlclient/hostinfo_linux.go +++ b/control/controlclient/hostinfo_linux.go @@ -11,6 +11,7 @@ "fmt" "io" "io/ioutil" + "os" "strings" "syscall" @@ -58,6 +59,9 @@ func osVersionLinux() string { if inContainer() { attrBuf.WriteString("; container") } + if inKnative() { + attrBuf.WriteString("; env=kn") + } attr := attrBuf.String() id := m["ID"] @@ -99,5 +103,21 @@ func inContainer() (ret bool) { } return nil }) + lineread.File("/proc/mounts", func(line []byte) error { + if mem.Contains(mem.B(line), mem.S("fuse.lxcfs")) { + ret = true + return io.EOF + } + return nil + }) return } + +func inKnative() bool { + // https://cloud.google.com/run/docs/reference/container-contract#env-vars + if os.Getenv("K_REVISION") != "" && os.Getenv("K_CONFIGURATION") != "" && + os.Getenv("K_SERVICE") != "" && os.Getenv("PORT") != "" { + return true + } + return false +}