Skip to content

Commit

Permalink
cleanup(libsinsp/test): update cri tests reflecting change in pod lab…
Browse files Browse the repository at this point in the history
…els handling

Signed-off-by: Melissa Kilby <[email protected]>
  • Loading branch information
incertum authored and poiana committed Dec 13, 2023
1 parent 5845581 commit 0672305
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 0672305

Please sign in to comment.