diff --git a/0009-lxcfs-tools-support-k8s-containerd-lxcfs-reliability.patch b/0009-lxcfs-tools-support-k8s-containerd-lxcfs-reliability.patch new file mode 100644 index 0000000000000000000000000000000000000000..d10040c750b71747928918720c2c750f3f386fd9 --- /dev/null +++ b/0009-lxcfs-tools-support-k8s-containerd-lxcfs-reliability.patch @@ -0,0 +1,115 @@ +From 7501d08e63f2146364e415a8dba4ff12955504f5 Mon Sep 17 00:00:00 2001 +From: yangjiaqi +Date: Thu, 29 May 2025 16:45:54 +0800 +Subject: [PATCH] lxcfs-tools support k8s+containerd+lxcfs reliability + +Signed-off-by: yangjiaqi +--- + remountcmd.go | 56 +++++++++++++++++++++++++++++++++++++++++---------- + 1 file changed, 45 insertions(+), 11 deletions(-) + +diff --git a/remountcmd.go b/remountcmd.go +index f1294a3..9d6ae95 100644 +--- a/remountcmd.go ++++ b/remountcmd.go +@@ -16,13 +16,13 @@ package main + + import ( + "bufio" ++ "encoding/json" + "fmt" + "io" + "io/ioutil" + "lxcfs-tools/libmount" + "os" + "os/exec" +- "encoding/json" + "strconv" + "strings" + "sync" +@@ -215,19 +215,20 @@ func remountAll(initMountns, initUserns string) error { + return nil + } + +-var ( +- runcStateDir = "/run/docker/runtime-runc/moby" ++const ( ++ dockerStateDir = "/run/docker/runtime-runc/moby" ++ k8sContainerdStateDir = "/run/containerd/runc/k8s.io" + ) + + type runcState struct { +- Id string `json:"id"` +- Pid int `json:"pid"` ++ Id string `json:"id"` ++ Pid int `json:"pid"` + } + +-func getRuncContainerIDAndPid() ([]string, error) { ++func getRuncContIdAndPid(runcStateDir string) ([]string, error) { + out, err := execCommond("runc", []string{"--root", runcStateDir, "list", "--format", "json"}) + if err != nil { +- return nil ,err ++ return nil, err + } + if out[0] == "" { + return out, nil +@@ -244,18 +245,51 @@ func getRuncContainerIDAndPid() ([]string, error) { + return res, nil + } + ++func getDockerContIdAndPid() ([]string, error) { ++ return getRuncContIdAndPid(dockerStateDir) ++} ++ ++func getContainerdK8sioContIdAndPid() ([]string, error) { ++ return getRuncContIdAndPid(k8sContainerdStateDir) ++} ++ ++func getIsulaContIdAndPid() ([]string, error) { ++ return execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"}) ++} ++ ++type stateGetter func() ([]string, error) ++ ++func dirExists(path string) bool { ++ fileInfo, err := os.Stat(path) ++ if err != nil { ++ return !os.IsNotExist(err) ++ } ++ return fileInfo.IsDir() ++} ++ ++func decideGetter() stateGetter { ++ if _, err := exec.LookPath("isula"); err == nil { ++ lxcfs_log.Info("use iSulad runtime") ++ return getIsulaContIdAndPid ++ } ++ if dirExists(dockerStateDir) { ++ lxcfs_log.Info("use Docker runtime") ++ return getDockerContIdAndPid ++ } ++ lxcfs_log.Info("use containerd runtime in namespace k8s.io") ++ return getContainerdK8sioContIdAndPid ++} ++ + func getContainerIDAndPid() ([]string, error) { + var ( + out []string + err error + ) + +- if _, err := exec.LookPath("isula"); err != nil { +- return getRuncContainerIDAndPid() +- } ++ var getContState stateGetter = decideGetter() + + for i := 0; i < 10; i++ { +- out, err = execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"}) ++ out, err = getContState() + if err == nil { + break + } +-- +2.33.0 + diff --git a/lxcfs-tools.spec b/lxcfs-tools.spec index fc7ad20b48852c27fefb2877671c2b70b87dc781..bd2eafb9696496bcf9acb272bae3ca5bb76e6de1 100644 --- a/lxcfs-tools.spec +++ b/lxcfs-tools.spec @@ -1,7 +1,7 @@ #Basic Information Name: lxcfs-tools Version: 0.3 -Release: 34 +Release: 35 Summary: toolkit for lxcfs to remount a running isulad License: Mulan PSL v2 URL: https://gitee.com/openeuler/lxcfs-tools @@ -16,6 +16,7 @@ Patch5: 0005-add-riscv64-to-syscall-build.patch Patch6: 0006-lxcfs-tools-support-lxcfs-reliability-for-doc.patch Patch7: 0007-test-add-tests-for-docker-and-lxcfs.patch Patch8: 0008-add-loong64-and-sw64-to-syscall-build.patch +Patch9: 0009-lxcfs-tools-support-k8s-containerd-lxcfs-reliability.patch Patch1000: lxcfs-tools-sw.patch @@ -109,6 +110,12 @@ rm -rfv %{buildroot} %changelog +* Thu May 29 2025 yangjiaqi - 0.3-35 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:support k8s+containerd+lxcfs reliability + * Thu Feb 22 2024 yangchenguang - 0.3-34 - Modify architecture support patch