From 0672305e1e625053c92d7235329bff06933ba6fa Mon Sep 17 00:00:00 2001 From: Melissa Kilby Date: Tue, 12 Dec 2023 20:38:06 +0000 Subject: [PATCH] cleanup(libsinsp/test): update cri tests reflecting change in pod labels handling Signed-off-by: Melissa Kilby --- .../container_parser_cri_containerd.ut.cpp | 14 ++++++++++---- .../container_parser_cri_crio.ut.cpp | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp b/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp index a362e7d2b5..1a510cb8ee 100644 --- a/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp +++ b/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp @@ -467,13 +467,11 @@ runtime::v1alpha2::ContainerStatusResponse get_default_cri_containerd_container_ auto status = resp.mutable_status(); status->set_id("3ad7b26ded6d8e7b23da7d48fe889434573036c27ae5a74837233de441c3601e"); status->set_state(runtime::v1alpha2::ContainerState::CONTAINER_RUNNING); // "CONTAINER_RUNNING" - status->set_created_at((uint64_t)1676262698000004577); // dummy - status->set_started_at((uint64_t)1676262698000004577); // dummy + status->set_created_at((uint64_t)1676262698000004577); // dummy + status->set_started_at((uint64_t)1676262698000004577); // dummy status->set_image_ref("docker.io/library/busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79"); status->mutable_image()->set_image("docker.io/library/busybox:latest"); auto labels = status->mutable_labels(); - // todo @incertum fix sinsp filterchecks to not rely on this label for pod id and labels retrieval as it could not always be present - (*labels)["io.kubernetes.sandbox.id"] = "63060edc2d3aa803ab559f2393776b151f99fc5b05035b21db66b3b62246ad6a"; (*labels)["io.kubernetes.container.name"] = "busybox"; (*labels)["io.kubernetes.pod.uid"] = "hdishddjaidwnduw9a43535366368"; (*labels)["io.kubernetes.pod.namespace"] = "default"; @@ -646,6 +644,14 @@ TEST_F(sinsp_with_test_input, container_parser_cri_containerd) ASSERT_EQ(1073741824, container.m_memory_limit); ASSERT_EQ(50000, container.m_cpu_quota); + if(root.isMember("sandboxID") && root["sandboxID"].isString()) + { + const auto pod_sandbox_id = root["sandboxID"].asString(); + // Add the pod sandbox id as label to the container. + // This labels is needed by the filterchecks code to get the pod labels. + container.m_labels["io.kubernetes.sandbox.id"] = pod_sandbox_id; + } + res = cri_api_v1alpha2->parse_cri_json_image(root, container); ASSERT_TRUE(res); ASSERT_EQ("busybox", container.m_imageid); // info.config.image.image can sometimes be in the format sha256: ... diff --git a/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp b/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp index 4661e85b58..af8fd9e4b1 100644 --- a/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp +++ b/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp @@ -459,13 +459,11 @@ runtime::v1alpha2::ContainerStatusResponse get_default_cri_crio_container_status auto status = resp.mutable_status(); status->set_id("49ecc282021562c567a8159ef424a06cdd8637efdca5953de9794eafe29adcad"); status->set_state(runtime::v1alpha2::ContainerState::CONTAINER_RUNNING); // "CONTAINER_RUNNING" - status->set_created_at((uint64_t)1676262698000004577); // dummy - status->set_started_at((uint64_t)1676262698000004577); // dummy + status->set_created_at((uint64_t)1676262698000004577); // dummy + status->set_started_at((uint64_t)1676262698000004577); // dummy status->set_image_ref("quay.io/crio/redis@sha256:1780b5a5496189974b94eb2595d86731d7a0820e4beb8ea770974298a943ed55"); status->mutable_image()->set_image("quay.io/crio/redis:alpine"); auto labels = status->mutable_labels(); - // todo @incertum fix sinsp filterchecks to not rely on this label for pod id and labels retrieval as it could not always be present - (*labels)["io.kubernetes.sandbox.id"] = "1f04600dc6949359da68eee5fe7c4069706a567c07d1ef89fe3bbfdeac7a6dca"; (*labels)["io.kubernetes.container.name"] = "redis"; (*labels)["io.kubernetes.pod.uid"] = "redhat-test-crio"; (*labels)["io.kubernetes.pod.namespace"] = "redhat.test.crio"; @@ -638,6 +636,14 @@ TEST_F(sinsp_with_test_input, container_parser_cri_crio) ASSERT_EQ(209715200, container.m_memory_limit); ASSERT_EQ(20000, container.m_cpu_quota); + if(root.isMember("sandboxID") && root["sandboxID"].isString()) + { + const auto pod_sandbox_id = root["sandboxID"].asString(); + // Add the pod sandbox id as label to the container. + // This labels is needed by the filterchecks code to get the pod labels. + container.m_labels["io.kubernetes.sandbox.id"] = pod_sandbox_id; + } + // // create and test sinsp_container_info for sandbox_container //