From b25538f670c51c914c6ef81cfa95d67f619b1151 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Thu, 17 Oct 2024 18:49:10 +0800 Subject: [PATCH] ci: Introduce CI to validate pod hostname Fixes #10422 Signed-off-by: alex.lyn --- .../integration/kubernetes/k8s-hostname.bats | 37 +++++++++++++++++++ .../kubernetes/run_kubernetes_tests.sh | 1 + .../runtimeclass_workloads/pod-hostname.yaml | 19 ++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/integration/kubernetes/k8s-hostname.bats create mode 100644 tests/integration/kubernetes/runtimeclass_workloads/pod-hostname.yaml diff --git a/tests/integration/kubernetes/k8s-hostname.bats b/tests/integration/kubernetes/k8s-hostname.bats new file mode 100644 index 0000000000..937c278494 --- /dev/null +++ b/tests/integration/kubernetes/k8s-hostname.bats @@ -0,0 +1,37 @@ +#!/usr/bin/env bats +# +# Copyright (c) 2024 Ant Group +# +# SPDX-License-Identifier: Apache-2.0 +# + +load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/tests_common.sh" + +setup() { + pod_name="test-pod-hostname" + get_pod_config_dir + + yaml_file="${pod_config_dir}/pod-hostname.yaml" + add_allow_all_policy_to_yaml "${yaml_file}" + + expected_name=$pod_name +} + +@test "Validate Pod hostname" { + # Create pod + kubectl apply -f "${yaml_file}" + + kubectl wait --for jsonpath=status.phase=Succeeded --timeout=$timeout pod "$pod_name" + + # Validate the pod hostname + result=$(kubectl logs $pod_name) + [ "$pod_name" == "$result" ] +} + +teardown() { + # Debugging information + kubectl describe "pod/$pod_name" + + kubectl delete pod "$pod_name" +} diff --git a/tests/integration/kubernetes/run_kubernetes_tests.sh b/tests/integration/kubernetes/run_kubernetes_tests.sh index 0daa55b112..7d4051d4c5 100755 --- a/tests/integration/kubernetes/run_kubernetes_tests.sh +++ b/tests/integration/kubernetes/run_kubernetes_tests.sh @@ -54,6 +54,7 @@ else "k8s-env.bats" \ "k8s-exec.bats" \ "k8s-file-volume.bats" \ + "k8s-hostname.bats" \ "k8s-inotify.bats" \ "k8s-job.bats" \ "k8s-kill-all-process-in-container.bats" \ diff --git a/tests/integration/kubernetes/runtimeclass_workloads/pod-hostname.yaml b/tests/integration/kubernetes/runtimeclass_workloads/pod-hostname.yaml new file mode 100644 index 0000000000..f99038b523 --- /dev/null +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-hostname.yaml @@ -0,0 +1,19 @@ +# +# Copyright (c) 2024 Ant Group. +# +# SPDX-License-Identifier: Apache-2.0 +# + +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-hostname +spec: + terminationGracePeriodSeconds: 0 + runtimeClassName: kata + restartPolicy: Never + containers: + - image: quay.io/prometheus/busybox:latest + name: pod-hostname-c01 + command: ["sh"] + args: ["-c", "hostname"]