From ec337acec99d1f4ed4c58fcad17d673fd739c1c2 Mon Sep 17 00:00:00 2001 From: bele Date: Tue, 24 Oct 2023 02:26:19 +0200 Subject: [PATCH] fix: enable kubernetes labels for k8s with containerd PR corresponding to the changes: https://github.com/hubblo-org/scaphandre/pull/327 --- Dockerfile | 6 +++--- src/sensors/utils.rs | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e622898e..bb337c84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.59 as planner +FROM rust:1.70 as planner WORKDIR app RUN cargo install cargo-chef @@ -7,7 +7,7 @@ COPY . . # Analyze dependencies RUN cargo chef prepare --recipe-path recipe.json -FROM rust:1.59 as cacher +FROM rust:1.70 as cacher WORKDIR app RUN cargo install cargo-chef COPY --from=planner /app/recipe.json recipe.json @@ -15,7 +15,7 @@ COPY --from=planner /app/recipe.json recipe.json # Cache dependencies RUN cargo chef cook --release --recipe-path recipe.json -FROM rust:1.59 as builder +FROM rust:1.70 as builder WORKDIR app COPY . . diff --git a/src/sensors/utils.rs b/src/sensors/utils.rs index 6748c3ba..f5ee911a 100644 --- a/src/sensors/utils.rs +++ b/src/sensors/utils.rs @@ -419,7 +419,7 @@ impl ProcessTracker { #[cfg(feature = "containers")] let regex_cgroup_docker = Regex::new(r"^.*/docker.*$").unwrap(); #[cfg(feature = "containers")] - let regex_cgroup_kubernetes = Regex::new(r"^/kubepods.*$").unwrap(); + let regex_cgroup_kubernetes = Regex::new(r"/kubepods.*$").unwrap(); #[cfg(feature = "containers")] let regex_cgroup_containerd = Regex::new("/system.slice/containerd.service/.*$").unwrap(); @@ -587,6 +587,12 @@ impl ProcessTracker { if container_id.contains("cri-containerd") { container_id = container_id.split(':').last().unwrap().to_string(); } + if container_id.starts_with("cri-containerd-") { + container_id = container_id + .strip_prefix("cri-containerd-") + .unwrap() + .to_string(); + } Ok(container_id) }