forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kata-containers#7132 from sprt/aks-volume-tests
tests: Add `k8s-volume` and `k8s-file-volume` tests to GHA CI
- Loading branch information
Showing
7 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Copyright (c) 2022 Ant Group | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
load "${BATS_TEST_DIRNAME}/../../common.bash" | ||
load "${BATS_TEST_DIRNAME}/tests_common.sh" | ||
TEST_INITRD="${TEST_INITRD:-no}" | ||
|
||
setup() { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
pod_name="test-file-volume" | ||
container_name="busybox-file-volume-container" | ||
tmp_file=$(exec_host mktemp /tmp/file-volume-test-foo.XXXXX) | ||
mount_path="/tmp/foo.txt" | ||
file_body="test" | ||
get_pod_config_dir | ||
} | ||
|
||
@test "Test readonly volume for pods" { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
# Write test body to temp file | ||
exec_host "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 | ||
|
||
# Create pod | ||
kubectl create -f "${pod_config_dir}/test-pod-file-volume.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_body" == "$file_in_container" ] | ||
} | ||
|
||
teardown() { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
kubectl delete pod "$pod_name" | ||
exec_host rm -f $tmp_file | ||
rm -f ${pod_config_dir}/test-pod-file-volume.yaml.yaml | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
load "${BATS_TEST_DIRNAME}/../../common.bash" | ||
load "${BATS_TEST_DIRNAME}/tests_common.sh" | ||
TEST_INITRD="${TEST_INITRD:-no}" | ||
|
||
setup() { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
|
||
get_pod_config_dir | ||
|
||
tmp_file=$(exec_host mktemp -d /tmp/data.XXXX) | ||
pod_yaml=$(mktemp --tmpdir pod_config.XXXXXX.yaml) | ||
msg="Hello from Kubernetes" | ||
exec_host "echo $msg > $tmp_file/index.html" | ||
pod_name="pv-pod" | ||
# Define temporary file at yaml | ||
sed -e "s|tmp_data|${tmp_file}|g" ${pod_config_dir}/pv-volume.yaml > "$pod_yaml" | ||
} | ||
|
||
@test "Create Persistent Volume" { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
|
||
volume_name="pv-volume" | ||
volume_claim="pv-claim" | ||
|
||
# Create the persistent volume | ||
kubectl create -f "$pod_yaml" | ||
|
||
# Check the persistent volume is Available | ||
cmd="kubectl get pv $volume_name | grep Available" | ||
waitForProcess "$wait_time" "$sleep_time" "$cmd" | ||
|
||
# Create the persistent volume claim | ||
kubectl create -f "${pod_config_dir}/volume-claim.yaml" | ||
|
||
# Check the persistent volume claim is Bound. | ||
cmd="kubectl get pvc $volume_claim | grep Bound" | ||
waitForProcess "$wait_time" "$sleep_time" "$cmd" | ||
|
||
# Create pod | ||
kubectl create -f "${pod_config_dir}/pv-pod.yaml" | ||
|
||
# Check pod creation | ||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" | ||
|
||
cmd="cat /mnt/index.html" | ||
kubectl exec $pod_name -- sh -c "$cmd" | grep "$msg" | ||
} | ||
|
||
teardown() { | ||
[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" | ||
|
||
# Debugging information | ||
kubectl describe "pod/$pod_name" | ||
|
||
kubectl delete pod "$pod_name" | ||
kubectl delete pvc "$volume_claim" | ||
kubectl delete pv "$volume_name" | ||
rm -f "$pod_yaml" | ||
exec_host rm -rf "$tmp_file" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/integration/kubernetes/runtimeclass_workloads/pv-pod.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: pv-pod | ||
spec: | ||
terminationGracePeriodSeconds: 0 | ||
runtimeClassName: kata | ||
volumes: | ||
- name: pv-storage | ||
persistentVolumeClaim: | ||
claimName: pv-claim | ||
containers: | ||
- name: pv-container | ||
image: quay.io/prometheus/busybox:latest | ||
ports: | ||
command: | ||
- sleep | ||
- "120" | ||
volumeMounts: | ||
- mountPath: "/mnt/" | ||
name: pv-storage |
19 changes: 19 additions & 0 deletions
19
tests/integration/kubernetes/runtimeclass_workloads/pv-volume.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: pv-volume | ||
labels: | ||
type: local | ||
spec: | ||
storageClassName: manual | ||
capacity: | ||
storage: 10Gi | ||
accessModes: | ||
- ReadWriteOnce | ||
hostPath: | ||
path: "tmp_data" |
16 changes: 16 additions & 0 deletions
16
tests/integration/kubernetes/runtimeclass_workloads/volume-claim.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: pv-claim | ||
spec: | ||
storageClassName: manual | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters