diff --git a/tests/integration/kubernetes/k8s-file-volume.bats b/tests/integration/kubernetes/k8s-file-volume.bats index 37ccd85f83..17f9725673 100644 --- a/tests/integration/kubernetes/k8s-file-volume.bats +++ b/tests/integration/kubernetes/k8s-file-volume.bats @@ -19,32 +19,49 @@ setup() { mount_path="/tmp/foo.txt" file_body="test" get_pod_config_dir -} -@test "Test readonly volume for pods" { # Write test body to temp file exec_host "$node" "echo "$file_body" > $tmp_file" # Create test yaml - sed -e "s|HOST_FILE|$tmp_file|" ${pod_config_dir}/pod-file-volume.yaml > ${pod_config_dir}/test-pod-file-volume.yaml - sed -i "s|MOUNT_PATH|$mount_path|" ${pod_config_dir}/test-pod-file-volume.yaml - sed -i "s|NODE|$node|" ${pod_config_dir}/test-pod-file-volume.yaml + test_yaml="${pod_config_dir}/test-pod-file-volume.yaml" + sed -e "s|HOST_FILE|$tmp_file|" ${pod_config_dir}/pod-file-volume.yaml > "${test_yaml}" + sed -i "s|MOUNT_PATH|$mount_path|" "${test_yaml}" + sed -i "s|NODE|$node|" "${test_yaml}" + + # Add policy to the yaml file + policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")" + + command="cat $mount_path" + add_exec_to_policy_settings "${policy_settings_dir}" "${command}" + + add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest" + auto_generate_policy "${policy_settings_dir}" "${test_yaml}" + + return 0 +} + +@test "Test readonly volume for pods" { # Create pod - kubectl create -f "${pod_config_dir}/test-pod-file-volume.yaml" + kubectl create -f "${test_yaml}" # Check pod creation kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" # Validate file volume body inside the pod - file_in_container=$(kubectl exec $pod_name -- cat $mount_path) + file_in_container=$(kubectl exec $pod_name -- $command) [ "$file_body" == "$file_in_container" ] } teardown() { [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" [ "${KATA_HYPERVISOR}" == "fc" ] && skip "test not working see: ${fc_limitations}" + + kubectl describe pod "$pod_name" + kubectl delete pod "$pod_name" exec_host "$node" rm -f $tmp_file - rm -f ${pod_config_dir}/test-pod-file-volume.yaml.yaml + rm -f "${test_yaml}" + delete_tmp_policy_settings_dir "${policy_settings_dir}" }