From 52d8ad28d24a8909f05f20e59d5572eb4a924335 Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Mon, 6 Jan 2025 11:20:57 +0000 Subject: [PATCH] chore(libsinsp): add some comments Signed-off-by: Roberto Scolaro --- userspace/libsinsp/container.h | 4 +++- userspace/libsinsp/container_engine/containerd.cpp | 3 +++ userspace/libsinsp/container_engine/cri.cpp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/userspace/libsinsp/container.h b/userspace/libsinsp/container.h index 1509cfa87f..77ae3c3e26 100644 --- a/userspace/libsinsp/container.h +++ b/userspace/libsinsp/container.h @@ -226,10 +226,12 @@ class sinsp_container_manager : public libsinsp::container_engine::container_cac * \brief do we want to start a new lookup for container metadata? * @param container_id the container id we want to look up * @param ctype the container engine that is doing the lookup + * @param engine_index index of container engine in case of multiple + * engines per container type * @return true if there's no lookup in progress and we're free to start * a new one, false otherwise * - * This method effectively checks if m_lookups[container_id][ctype] + * This method effectively checks if m_lookups[container_id][ctype][engine_index] * exists, without creating unnecessary map entries along the way. */ bool should_lookup(const std::string& container_id, diff --git a/userspace/libsinsp/container_engine/containerd.cpp b/userspace/libsinsp/container_engine/containerd.cpp index 8a8719ed8f..8659b00250 100644 --- a/userspace/libsinsp/container_engine/containerd.cpp +++ b/userspace/libsinsp/container_engine/containerd.cpp @@ -27,6 +27,9 @@ limitations under the License. using namespace libsinsp::container_engine; using namespace libsinsp::runc; +// Containers created via ctr use the "default" namespace (instead of the cri "k8s.io" namespace) +// which will result in the `/default` cgroup path. +// https://github.com/containerd/containerd/blob/3b15606e196e450cf817fa9f835ab5324b35a28b/pkg/namespaces/context.go#L32 constexpr const cgroup_layout CONTAINERD_CGROUP_LAYOUT[] = {{"/default/", ""}, {nullptr, nullptr}}; constexpr const std::string_view CONTAINERD_SOCKETS[] = { diff --git a/userspace/libsinsp/container_engine/cri.cpp b/userspace/libsinsp/container_engine/cri.cpp index 25a03e1822..56203ef587 100644 --- a/userspace/libsinsp/container_engine/cri.cpp +++ b/userspace/libsinsp/container_engine/cri.cpp @@ -245,6 +245,8 @@ bool cri::resolve(sinsp_threadinfo *tinfo, bool query_os_for_missing_info) { } else { cache->notify_new_container(container, tinfo); } + // note: with more than one container runtime we cannot be sure if a resolution is enough + // and we have to query all the runtimes. return false; }