From 3c2f0f2877fc8a1645a65b2672f6e3806c2b0975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Min=C3=A1=C5=99?= Date: Wed, 13 Sep 2023 18:55:01 +0200 Subject: [PATCH] Version v1.1.0 - Nerdctl support (@miminar) --- README.md | 3 ++- internal/containerinfo/containerinfo.go | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a9bdd19..d7f926b 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,8 @@ If desired pod is still initializing, nsenter will pick currently running contai Container Runtimes Clients: - docker; -- crictl. +- crictl - expected to be present on nodes with cri-o runtime; +- nerdctl - expected to be present on nodes with containerd runtime; crictl will be used as a fallback. OS: diff --git a/internal/containerinfo/containerinfo.go b/internal/containerinfo/containerinfo.go index e05f187..b21617a 100644 --- a/internal/containerinfo/containerinfo.go +++ b/internal/containerinfo/containerinfo.go @@ -10,6 +10,11 @@ import ( v1 "k8s.io/api/core/v1" ) +const containerdShellCmd = `"if command -v nerdctl >/dev/null 2>&1; then + exec nerdctl inspect %[1]s --format {{.State.Pid}} +fi +exec crictl inspect --output go-template --template={{.info.pid}} %[1]s"` + type ContainerInfo struct { NodeName string NodeIP string @@ -101,7 +106,16 @@ func GetPidDiscoverCommand(containerInfo *ContainerInfo) ([]string, error) { "--format", "{{.State.Pid}}", }, nil - case "containerd", "cri-o": + + case "containerd": + return []string{ + "sudo", + "sh", + "-c", + fmt.Sprintf(containerdShellCmd, containerInfo.ContainerID), + }, nil + + case "cri-o": return []string{ "sudo", "crictl",