2

我正在尝试使用 golang 检索 cri-o 信息,例如 containerID、pid。下面提到的代码在我的 mac 中工作,但是当我将它容器化并将其部署在 openshift 3.11 堆栈上时,它不起作用。

cmdStr在下面提到的代码中可以是任何 docker 或 cri-o 命令,例如docker pscrictl ps --no-trunc -a --quiet

使用的 go 版本是go1.14.1 darwin/amd64

package main

import "os/exec"
import "fmt"

func main() {
    cmdStr := "docker ps"
    fmt.Printf("cmdStr is %s", cmdStr)
    out, _ := exec.Command("/bin/sh", "-c", cmdStr).Output()
    fmt.Printf("output is %s", out)
}

我在我的 Mac 上得到的上述代码的输出是

cmdStr is docker ps
output is CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

在 pod 的日志中,openshift 3.11 上的相同是:

cmdStr is docker ps
output is

另一种选择是使用此链接中的代码:https ://godoc.org/github.com/google/cadvisor/container/crio#pkg-subdirectories但我不知道如何使用它,一个例子会有所帮助.

go get github.com/google/cadvisor/container/crio

github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:86:31: undefined: unix.CGROUP_SUPER_MAGIC
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:95:5: undefined: IsCgroup2UnifiedMode
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:109:5: undefined: IsCgroup2UnifiedMode
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:151:5: undefined: IsCgroup2UnifiedMode
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:155:18: undefined: ParseCgroupFile
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:163:9: undefined: Mount
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:171:75: undefined: Mount
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:172:16: undefined: Mount
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:185:8: undefined: Mount
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:209:37: undefined: Mount
github.com/opencontainers/runc/libcontainer/cgroups/v1_utils.go:185:8: too many errors
# github.com/opencontainers/runc/libcontainer/utils
github.com/opencontainers/runc/libcontainer/utils/utils_unix.go:19:17: undefined: unix.PROC_SUPER_MAGIC
github.com/opencontainers/runc/libcontainer/utils/utils_unix.go:63:62: undefined: unix.SOCK_CLOEXEC
4

0 回答 0