From 36ea1b8ee7b0336eafb8e97228507da6ef3d102b Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Thu, 19 Oct 2023 15:24:52 -0300 Subject: [PATCH] tests/k8s: add new_pod_config() to lib.sh Copied the new_pod_config() and pod-config.yaml.in from CCv0 branch tests' integration/kubernetes/confidential/tests_common.sh and fixtures. Unlike the original version, new_pod_config() now gets the runtimeclass by parameter as the RUNTIMECLASS environment variable seems not broadly used on main branch's CI. The pod-config.yaml.in was changed as the diff shows below. In particular the imagePullSecrets was removed to avoid it throwing a warning on the pod's log. ``` --- a/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in @@ -5,12 +5,10 @@ apiVersion: v1 kind: Pod metadata: - name: busybox-cc + name: test-e2e spec: runtimeClassName: $RUNTIMECLASS containers: - - name: nginx + - name: test_container image: $IMAGE - imagePullPolicy: Always - imagePullSecrets: - - name: cococred \ No newline at end of file + imagePullPolicy: Always \ No newline at end of file ``` Co-authored-by: Georgina Kinge Co-authored-by: Megan Wright Co-authored-by: stevenhorsman Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/lib.sh | 27 +++++++++++++++++++ .../runtimeclass_workloads/pod-config.yaml.in | 14 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in diff --git a/tests/integration/kubernetes/lib.sh b/tests/integration/kubernetes/lib.sh index 57fbf27080..133170041e 100644 --- a/tests/integration/kubernetes/lib.sh +++ b/tests/integration/kubernetes/lib.sh @@ -15,6 +15,8 @@ k8s_delete_all_pods_if_any_exists() { kubectl delete --all pods } +FIXTURES_DIR="${BATS_TEST_DIRNAME}/runtimeclass_workloads" + # Wait until the pod is not 'Ready'. Fail if it hits the timeout. # # Parameters: @@ -71,4 +73,29 @@ assert_pod_fail() { echo "Attempt to create the container but it should fail" ! k8s_create_pod "$container_config" || /bin/false +} + +# Create a pod configuration out of a template file. +# +# Parameters: +# $1 - the container image. +# $2 - the runtimeclass +# +# Return: +# the path to the configuration file. The caller should not care about +# its removal afterwards as it is created under the bats temporary +# directory. +# +new_pod_config() { + local base_config="${FIXTURES_DIR}/pod-config.yaml.in" + local image="$1" + local runtimeclass="$2" + local new_config + + # The runtimeclass is not optional. + [ -n "$runtimeclass" ] || return 1 + + new_config=$(mktemp "${BATS_FILE_TMPDIR}/$(basename "${base_config}").XXX") + IMAGE="$image" RUNTIMECLASS="$runtimeclass" envsubst < "$base_config" > "$new_config" + echo "$new_config" } \ No newline at end of file diff --git a/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in b/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in new file mode 100644 index 0000000000..b79032d445 --- /dev/null +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in @@ -0,0 +1,14 @@ +# Copyright (c) 2021, 2022 IBM Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +apiVersion: v1 +kind: Pod +metadata: + name: test-e2e +spec: + runtimeClassName: $RUNTIMECLASS + containers: + - name: test-container + image: $IMAGE + imagePullPolicy: Always