Skip to content

Commit

Permalink
Feat: Add option to filter processes by both containers and nodes (#27)
Browse files Browse the repository at this point in the history
* Feat: Add option to filter processes by both containers and nodes
- Part of #2110 in testsuite

Signed-off-by: svteb <slavo.valko@tietoevry.com>
Co-authored-by: Konstantin <kosstenn4uk@yandex.ru>

---------

Signed-off-by: svteb <slavo.valko@tietoevry.com>
Co-authored-by: Martin Matyas <martin.matyas@gmail.com>
Co-authored-by: Konstantin <kosstenn4uk@yandex.ru>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent 71f9497 commit 0b8f04b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cluster_tools.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0b8f04b

Please sign in to comment.