mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-03-18 02:32:26 +00:00
Compare commits
3 Commits
3.28.0
...
runtime-rs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db5552a097 | ||
|
|
8bcb6ad64b | ||
|
|
3e6bab0f1b |
@@ -30,10 +30,12 @@ setup() {
|
|||||||
|
|
||||||
@test "Running with postStart and preStop handlers" {
|
@test "Running with postStart and preStop handlers" {
|
||||||
# Create the pod with postStart and preStop handlers
|
# Create the pod with postStart and preStop handlers
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check postStart message
|
# Check postStart message
|
||||||
check_postStart=$(kubectl exec $pod_name -- "${exec_command[@]}")
|
check_postStart=$(kubectl exec $pod_name -- "${exec_command[@]}")
|
||||||
|
|||||||
@@ -82,8 +82,9 @@ setup() {
|
|||||||
auto_generate_policy "${policy_settings_dir}" "${tmp_pod_yaml}"
|
auto_generate_policy "${policy_settings_dir}" "${tmp_pod_yaml}"
|
||||||
|
|
||||||
# Start the workload.
|
# Start the workload.
|
||||||
kubectl create -f "$tmp_pod_yaml"
|
# kubectl create -f "$tmp_pod_yaml"
|
||||||
kubectl wait --for condition=ready --timeout=$timeout "pod/${pod_name}"
|
# kubectl wait --for condition=ready --timeout=$timeout "pod/${pod_name}"
|
||||||
|
k8s_create_pod_ready "${pod_name}" "$tmp_pod_yaml"
|
||||||
|
|
||||||
# Verify persistent volume claim is bound
|
# Verify persistent volume claim is bound
|
||||||
kubectl get "pvc/${volume_claim}" | grep "Bound"
|
kubectl get "pvc/${volume_claim}" | grep "Bound"
|
||||||
|
|||||||
@@ -40,9 +40,10 @@ setup() {
|
|||||||
|
|
||||||
@test "Check capabilities of pod" {
|
@test "Check capabilities of pod" {
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Verify expected capabilities for the running container. Add retry to ensure
|
# Verify expected capabilities for the running container. Add retry to ensure
|
||||||
# that the container had time to execute:
|
# that the container had time to execute:
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ setup() {
|
|||||||
kubectl get configmaps $config_name -o yaml | grep -q "data-"
|
kubectl get configmaps $config_name -o yaml | grep -q "data-"
|
||||||
|
|
||||||
# Create a pod that consumes the ConfigMap
|
# Create a pod that consumes the ConfigMap
|
||||||
kubectl create -f "${pod_yaml_file}"
|
# kubectl create -f "${pod_yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${pod_yaml_file}"
|
||||||
|
|
||||||
# Check env
|
# Check env
|
||||||
grep_pod_exec_output "${pod_name}" "KUBE_CONFIG_1=value-1" "${exec_command[@]}"
|
grep_pod_exec_output "${pod_name}" "KUBE_CONFIG_1=value-1" "${exec_command[@]}"
|
||||||
|
|||||||
@@ -41,10 +41,11 @@ setup() {
|
|||||||
auto_generate_policy "${policy_settings_dir}" "${pod_config}"
|
auto_generate_policy "${policy_settings_dir}" "${pod_config}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config}"
|
# kubectl create -f "${pod_config}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
#kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${pod_config}"
|
||||||
|
|
||||||
# Create a file
|
# Create a file
|
||||||
echo "$content" > "$file_name"
|
echo "$content" > "$file_name"
|
||||||
@@ -78,10 +79,11 @@ setup() {
|
|||||||
auto_generate_policy "${policy_settings_dir}" "${pod_config}"
|
auto_generate_policy "${policy_settings_dir}" "${pod_config}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config}"
|
# kubectl create -f "${pod_config}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${pod_config}"
|
||||||
|
|
||||||
kubectl logs "$pod_name" || true
|
kubectl logs "$pod_name" || true
|
||||||
kubectl describe pod "$pod_name" || true
|
kubectl describe pod "$pod_name" || true
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ setup() {
|
|||||||
|
|
||||||
@test "Kubectl exec" {
|
@test "Kubectl exec" {
|
||||||
# Create the pod
|
# Create the pod
|
||||||
kubectl create -f "${test_yaml_file}"
|
# kubectl create -f "${test_yaml_file}"
|
||||||
|
|
||||||
# Get pod specification
|
# Get pod specification
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${test_yaml_file}"
|
||||||
|
|
||||||
# Run commands in Pod
|
# Run commands in Pod
|
||||||
## Cases for -it options
|
## Cases for -it options
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ setup() {
|
|||||||
|
|
||||||
@test "Test readonly volume for pods" {
|
@test "Test readonly volume for pods" {
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${test_yaml}"
|
# kubectl create -f "${test_yaml}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${test_yaml}"
|
||||||
|
|
||||||
# Validate file volume body inside the pod
|
# Validate file volume body inside the pod
|
||||||
file_in_container=$(kubectl exec $pod_name -- "${command[@]}")
|
file_in_container=$(kubectl exec $pod_name -- "${command[@]}")
|
||||||
|
|||||||
@@ -37,10 +37,11 @@ setup() {
|
|||||||
kubectl create -f "$configmap_yaml"
|
kubectl create -f "$configmap_yaml"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_yaml}"
|
# kubectl create -f "${pod_yaml}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${pod_yaml}"
|
||||||
|
|
||||||
# Get pod ip
|
# Get pod ip
|
||||||
pod_ip=$(kubectl get pod $pod_name --template={{.status.podIP}})
|
pod_ip=$(kubectl get pod $pod_name --template={{.status.podIP}})
|
||||||
|
|||||||
@@ -88,7 +88,11 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
|
|
||||||
echo "Kata pod test-e2e from authenticated image is running"
|
echo "Kata pod test-e2e from authenticated image is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +136,11 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
|
|
||||||
echo "Kata pod test-e2e from authenticated image is running"
|
echo "Kata pod test-e2e from authenticated image is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,11 @@ function setup_kbs_decryption_key() {
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
|
|
||||||
echo "Kata pod test-e2e from encrypted image is running"
|
echo "Kata pod test-e2e from encrypted image is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +127,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +156,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +176,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +213,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +249,10 @@ EOF
|
|||||||
# For debug sake
|
# For debug sake
|
||||||
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
echo "Pod ${kata_pod}: $(cat ${kata_pod})"
|
||||||
|
|
||||||
k8s_create_pod "${kata_pod}"
|
# Default wait timeout is 120
|
||||||
|
local wait_time=120
|
||||||
|
[[ "${KATA_HYPERVISOR}" == qemu-coco-dev-runtime-rs ]] && wait_time=300
|
||||||
|
k8s_create_pod "${kata_pod}" "$wait_time"
|
||||||
echo "Kata pod test-e2e from image security policy is running"
|
echo "Kata pod test-e2e from image security policy is running"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "/dev hostPath volume bind mounts the guest device and skips virtio-fs" {
|
@test "/dev hostPath volume bind mounts the guest device and skips virtio-fs" {
|
||||||
kubectl apply -f "${yaml_file}"
|
# kubectl apply -f "${yaml_file}"
|
||||||
kubectl wait --for=condition=Ready --timeout="${timeout}" pod "${pod_name}"
|
# kubectl wait --for=condition=Ready --timeout="${timeout}" pod "${pod_name}"
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check the mount info.
|
# Check the mount info.
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ setup() {
|
|||||||
|
|
||||||
@test "Kill all processes in container" {
|
@test "Kill all processes in container" {
|
||||||
# Create the pod
|
# Create the pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check PID from first container
|
# Check PID from first container
|
||||||
first_pid_container=$(kubectl exec $pod_name -c $first_container_name \
|
first_pid_container=$(kubectl exec $pod_name -c $first_container_name \
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ setup() {
|
|||||||
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check liveness probe returns a success code
|
# Check liveness probe returns a success code
|
||||||
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
||||||
@@ -52,10 +53,11 @@ setup() {
|
|||||||
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check liveness probe returns a success code
|
# Check liveness probe returns a success code
|
||||||
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
||||||
@@ -78,10 +80,11 @@ setup() {
|
|||||||
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
auto_generate_policy "${pod_config_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check liveness probe returns a success code
|
# Check liveness probe returns a success code
|
||||||
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
kubectl describe pod "$pod_name" | grep -E "Liveness|#success=1"
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ setup() {
|
|||||||
|
|
||||||
@test "Verify nginx connectivity between pods" {
|
@test "Verify nginx connectivity between pods" {
|
||||||
|
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
# kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
||||||
kubectl expose deployment/${deployment}
|
# Retries
|
||||||
|
k8s_create_deployment_ready "${yaml_file}" ${deployment}
|
||||||
|
kubectl expose deployment/${deployment} ${deployment}
|
||||||
|
|
||||||
busybox_pod="test-nginx"
|
busybox_pod="test-nginx"
|
||||||
kubectl run $busybox_pod --restart=Never -it --image="$busybox_image" \
|
kubectl run $busybox_pod --restart=Never -it --image="$busybox_image" \
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ setup() {
|
|||||||
|
|
||||||
@test "Test OOM events for pods" {
|
@test "Test OOM events for pods" {
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${yaml_file}"
|
# kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
#kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retries
|
||||||
|
k8s_create_pod_ready "${pod_name}" "${yaml_file}"
|
||||||
|
|
||||||
# Check if OOMKilled
|
# Check if OOMKilled
|
||||||
container_name=$(kubectl get pod "$pod_name" -o jsonpath='{.status.containerStatuses[0].name}')
|
container_name=$(kubectl get pod "$pod_name" -o jsonpath='{.status.containerStatuses[0].name}')
|
||||||
|
|||||||
@@ -34,10 +34,11 @@ setup() {
|
|||||||
kubectl create configmap "$config_name"
|
kubectl create configmap "$config_name"
|
||||||
|
|
||||||
# Create a pod that consumes the "empty-config" and "optional-missing-config" ConfigMaps as volumes
|
# Create a pod that consumes the "empty-config" and "optional-missing-config" ConfigMaps as volumes
|
||||||
kubectl create -f "${pod_yaml}"
|
# kubectl create -f "${pod_yaml}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
# kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
|
# Retry for ready pod
|
||||||
|
k8s_create_pod_ready "$pod_name" "${pod_yaml}"
|
||||||
|
|
||||||
# Check configmap folders exist
|
# Check configmap folders exist
|
||||||
kubectl exec $pod_name -- "${exec_empty_command[@]}"
|
kubectl exec $pod_name -- "${exec_empty_command[@]}"
|
||||||
|
|||||||
@@ -51,22 +51,66 @@ setup() {
|
|||||||
|
|
||||||
# Common function for all test cases that expect CreateContainer to be blocked by policy.
|
# Common function for all test cases that expect CreateContainer to be blocked by policy.
|
||||||
test_job_policy_error() {
|
test_job_policy_error() {
|
||||||
# Initiate job creation
|
local max_attempts=5
|
||||||
kubectl apply -f "${incorrect_yaml}"
|
local attempt_num
|
||||||
|
local sleep_between_attempts=5
|
||||||
|
|
||||||
# Wait for the job to be created
|
for attempt_num in $(seq 1 "${max_attempts}"); do
|
||||||
cmd="kubectl describe job ${job_name} | grep SuccessfulCreate"
|
info "Starting attempt #${attempt_num}"
|
||||||
info "Waiting for: ${cmd}"
|
|
||||||
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}" || return 1
|
|
||||||
|
|
||||||
# List the pods that belong to the job
|
# Cleanup possible previous resources
|
||||||
pod_names=$(kubectl get pods "--selector=job-name=${job_name}" --output=jsonpath='{.items[*].metadata.name}')
|
kubectl delete -f "${incorrect_yaml}" --ignore-not-found=true --now --timeout=120s
|
||||||
info "pod_names: ${pod_names}"
|
|
||||||
|
|
||||||
# CreateContainerRequest must have been denied by the policy.
|
# 1. Apply Job
|
||||||
for pod_name in ${pod_names[@]}; do
|
kubectl apply -f "${incorrect_yaml}"
|
||||||
wait_for_blocked_request "CreateContainerRequest" "${pod_name}" || return 1
|
if [ $? -ne 0 ]; then
|
||||||
|
warn "Failed to apply Job. Retrying..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2. Wait for Job creation event
|
||||||
|
cmd="kubectl describe job ${job_name} | grep SuccessfulCreate"
|
||||||
|
info "Waiting for: ${cmd}"
|
||||||
|
|
||||||
|
run waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
||||||
|
if [ "$status" -ne 0 ]; then
|
||||||
|
warn "waitForProcess FAILED on attempt #${attempt_num}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Get pod list
|
||||||
|
pod_names=$(kubectl get pods "--selector=job-name=${job_name}" --output=jsonpath='{.items[*].metadata.name}')
|
||||||
|
info "pod_names: ${pod_names}"
|
||||||
|
|
||||||
|
if [ -z "${pod_names}" ]; then
|
||||||
|
warn "No pods found for job. Retrying..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. Check each pod for blocked CreateContainerRequest
|
||||||
|
for pod_name in ${pod_names[@]}; do
|
||||||
|
info "Checking pod: ${pod_name}"
|
||||||
|
|
||||||
|
run wait_for_blocked_request "CreateContainerRequest" "${pod_name}"
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
info "wait_for_blocked_request succeeded for pod ${pod_name} on attempt #${attempt_num}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
warn "wait_for_blocked_request FAILED for pod ${pod_name} on attempt #${attempt_num}"
|
||||||
|
# We break pod loop, but the attempt will continue
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Retry if not last attempt
|
||||||
|
if [ "${attempt_num}" -lt "${max_attempts}" ]; then
|
||||||
|
info "Retrying in ${sleep_between_attempts} seconds..."
|
||||||
|
sleep "${sleep_between_attempts}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
error "Test failed after ${max_attempts} attempts."
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected environment variable" {
|
@test "Policy failure: unexpected environment variable" {
|
||||||
@@ -76,6 +120,8 @@ test_job_policy_error() {
|
|||||||
"${incorrect_yaml}"
|
"${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected command line argument" {
|
@test "Policy failure: unexpected command line argument" {
|
||||||
@@ -85,6 +131,8 @@ test_job_policy_error() {
|
|||||||
"${incorrect_yaml}"
|
"${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected emptyDir volume" {
|
@test "Policy failure: unexpected emptyDir volume" {
|
||||||
@@ -98,6 +146,8 @@ test_job_policy_error() {
|
|||||||
"${incorrect_yaml}"
|
"${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected projected volume" {
|
@test "Policy failure: unexpected projected volume" {
|
||||||
@@ -122,6 +172,8 @@ test_job_policy_error() {
|
|||||||
' "${incorrect_yaml}"
|
' "${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected readOnlyRootFilesystem" {
|
@test "Policy failure: unexpected readOnlyRootFilesystem" {
|
||||||
@@ -131,6 +183,8 @@ test_job_policy_error() {
|
|||||||
"${incorrect_yaml}"
|
"${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected UID = 222" {
|
@test "Policy failure: unexpected UID = 222" {
|
||||||
@@ -140,6 +194,8 @@ test_job_policy_error() {
|
|||||||
"${incorrect_yaml}"
|
"${incorrect_yaml}"
|
||||||
|
|
||||||
test_job_policy_error
|
test_job_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
|||||||
@@ -130,9 +130,47 @@ create_and_wait_for_pod_ready() {
|
|||||||
|
|
||||||
# Common function for several test cases from this bats script.
|
# Common function for several test cases from this bats script.
|
||||||
test_pod_policy_error() {
|
test_pod_policy_error() {
|
||||||
kubectl create -f "${correct_configmap_yaml}"
|
local max_attempts=5
|
||||||
kubectl create -f "${incorrect_pod_yaml}"
|
local attempt_num
|
||||||
wait_for_blocked_request "CreateContainerRequest" "${pod_name}"
|
local sleep_between_attempts=5
|
||||||
|
|
||||||
|
for attempt_num in $(seq 1 "${max_attempts}"); do
|
||||||
|
info "Starting attempt #${attempt_num}"
|
||||||
|
kubectl delete -f "${incorrect_pod_yaml}" --ignore-not-found=true --now --timeout=120s
|
||||||
|
kubectl delete -f "${correct_configmap_yaml}" --ignore-not-found=true
|
||||||
|
|
||||||
|
# Create ConfigMap
|
||||||
|
kubectl create -f "${correct_configmap_yaml}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
warn "Failed to create ConfigMap. Retrying..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the incorrect pod (expected to be blocked)
|
||||||
|
kubectl create -f "${incorrect_pod_yaml}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
warn "Failed to create Pod. Retrying..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wait for CreateContainerRequest to be blocked
|
||||||
|
run wait_for_blocked_request "CreateContainerRequest" "${pod_name}"
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
info "wait_for_blocked_request succeeded on attempt #${attempt_num}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
warn "wait_for_blocked_request FAILED on attempt #${attempt_num}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retry if not the last attempt
|
||||||
|
if [ "${attempt_num}" -lt "${max_attempts}" ]; then
|
||||||
|
info "Retrying in ${sleep_between_attempts} seconds..."
|
||||||
|
sleep "${sleep_between_attempts}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
error "Test failed after ${max_attempts} attempts."
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected container image" {
|
@test "Policy failure: unexpected container image" {
|
||||||
@@ -143,6 +181,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected privileged security context" {
|
@test "Policy failure: unexpected privileged security context" {
|
||||||
@@ -152,6 +192,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected terminationMessagePath" {
|
@test "Policy failure: unexpected terminationMessagePath" {
|
||||||
@@ -161,6 +203,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected hostPath volume mount" {
|
@test "Policy failure: unexpected hostPath volume mount" {
|
||||||
@@ -174,6 +218,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected config map" {
|
@test "Policy failure: unexpected config map" {
|
||||||
@@ -265,6 +311,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Policy failure: unexpected UID = 1234" {
|
@test "Policy failure: unexpected UID = 1234" {
|
||||||
@@ -276,6 +324,8 @@ test_pod_policy_error() {
|
|||||||
"${incorrect_pod_yaml}"
|
"${incorrect_pod_yaml}"
|
||||||
|
|
||||||
test_pod_policy_error
|
test_pod_policy_error
|
||||||
|
test_result=$?
|
||||||
|
[ "${test_result}" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
|||||||
@@ -24,8 +24,11 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "Scale nginx deployment" {
|
@test "Scale nginx deployment" {
|
||||||
kubectl create -f "${test_yaml}"
|
# kubectl create -f "${test_yaml}"
|
||||||
kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
# kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
||||||
|
# Retries
|
||||||
|
k8s_create_deployment_ready "${test_yaml}" ${deployment}
|
||||||
|
|
||||||
kubectl expose deployment/${deployment}
|
kubectl expose deployment/${deployment}
|
||||||
kubectl scale deployment/${deployment} --replicas=${replicas}
|
kubectl scale deployment/${deployment} --replicas=${replicas}
|
||||||
cmd="kubectl get deployment/${deployment} -o yaml | grep 'availableReplicas: ${replicas}'"
|
cmd="kubectl get deployment/${deployment} -o yaml | grep 'availableReplicas: ${replicas}'"
|
||||||
|
|||||||
@@ -420,6 +420,80 @@ wait_for_blocked_request() {
|
|||||||
waitForProcess "${wait_time}" "${sleep_time}" "${command}" >/dev/null 2>/dev/null
|
waitForProcess "${wait_time}" "${sleep_time}" "${command}" >/dev/null 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# k8s create a ready pod
|
||||||
|
k8s_create_pod_ready() {
|
||||||
|
local pod_name="$1"
|
||||||
|
local pod_yaml="$2"
|
||||||
|
local wait_time="${3:-300}"
|
||||||
|
local max_attempts="${4:-5}"
|
||||||
|
|
||||||
|
local attempt_num
|
||||||
|
|
||||||
|
for attempt_num in $(seq 1 "${max_attempts}"); do
|
||||||
|
# First,forcefully deleting resources
|
||||||
|
kubectl delete -f "${pod_yaml}" --ignore-not-found=true --now --timeout=$timeout
|
||||||
|
|
||||||
|
kubectl create -f "${pod_yaml}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
# Failed to create Pod.Aborting test.
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check pod creation
|
||||||
|
run kubectl wait --for=condition=Ready --timeout="${wait_time}s" pod "${pod_name}"
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
# Test Succeeded on attempt #${attempt_num}
|
||||||
|
info "Waiting ${wait_time} seconds for pod ${pod_name} Ready."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retry
|
||||||
|
if [ "${attempt_num}" -lt "${max_attempts}" ]; then
|
||||||
|
info "Waiting for 5 seconds before next attempt..."
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
info "Test Failed after ${max_attempts} attempts for pod ${pod_name}."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
k8s_create_deployment_ready() {
|
||||||
|
local deployment_yaml="$1"
|
||||||
|
local deployment="$2"
|
||||||
|
|
||||||
|
local wait_time=300
|
||||||
|
local max_attempts=5
|
||||||
|
local attempt_num
|
||||||
|
|
||||||
|
for attempt_num in $(seq 1 "${max_attempts}"); do
|
||||||
|
# First,forcefully deleting resources
|
||||||
|
kubectl delete -f "${deployment_yaml}" --ignore-not-found=true --now --timeout=$timeout
|
||||||
|
|
||||||
|
kubectl create -f "${deployment_yaml}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
# Failed to create Pod.Aborting test.
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check deployment ready
|
||||||
|
run kubectl wait --for=condition=Available --timeout="${wait_time}s" deployment/${deployment}
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
# Test Succeeded on attempt #${attempt_num}
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retry
|
||||||
|
if [ "${attempt_num}" -lt "${max_attempts}" ]; then
|
||||||
|
info "Waiting for 5 seconds before next attempt..."
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
#Test Failed after ${max_attempts} attempts.
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Execute in a pod a command that is allowed by policy.
|
# Execute in a pod a command that is allowed by policy.
|
||||||
pod_exec_allowed_command() {
|
pod_exec_allowed_command() {
|
||||||
local -r pod_name="$1"
|
local -r pod_name="$1"
|
||||||
|
|||||||
Reference in New Issue
Block a user