From 0b8f04b0b63dedf0f69f7e5180bdb6ebef718a88 Mon Sep 17 00:00:00 2001 From: Slavo <133103846+svteb@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:40:05 +0200 Subject: [PATCH] Feat: Add option to filter processes by both containers and nodes (#27) * Feat: Add option to filter processes by both containers and nodes - Part of #2110 in testsuite Signed-off-by: svteb Co-authored-by: Konstantin --------- Signed-off-by: svteb Co-authored-by: Martin Matyas Co-authored-by: Konstantin --- cluster_tools.cr | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cluster_tools.cr b/cluster_tools.cr index 8d28d632..8ce26137 100644 --- a/cluster_tools.cr +++ b/cluster_tools.cr @@ -163,7 +163,7 @@ module ClusterTools pid end #each_container_by_resource(resource, namespace) do | container_id, container_pid_on_node, node, container_proctree_statuses, container_status| - def self.all_containers_by_resource?(resource, namespace, &block) + def self.all_containers_by_resource?(resource, namespace, only_container_pids : Bool = false, &block) kind = resource["kind"].downcase case kind when "deployment","statefulset","pod","replicaset", "daemonset" @@ -210,8 +210,12 @@ module ClusterTools node_name = node.dig("metadata", "name").as_s Log.info { "node name : #{node_name}" } - pids = KernelIntrospection::K8s::Node.pids(node) - Log.info { "proctree_by_pid pids: #{pids}" } + if only_container_pids + pids = KernelIntrospection::K8s::Node.pids_by_container(container_id, node) + else + pids = KernelIntrospection::K8s::Node.pids(node) + end + Log.info { "parsed pids: #{pids}" } proc_statuses = KernelIntrospection::K8s::Node.all_statuses_by_pids(pids, node) container_proctree_statuses = KernelIntrospection::K8s::Node.proctree_by_pid(container_pid_on_node, node, proc_statuses)