forked from clearcontainers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
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 clearcontainers#922 from GabyCT/topic/addvolumek8s
tests: Add K8s tests for persistent volumes
- Loading branch information
Showing
5 changed files
with
113 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,50 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh" | ||
|
||
setup() { | ||
export KUBECONFIG=/etc/kubernetes/admin.conf | ||
pod_config_dir="${BATS_TEST_DIRNAME}/untrusted_workloads" | ||
tmp_file=$(mktemp -d /tmp/data.XXXX) | ||
msg="Hello from Kubernetes" | ||
echo $msg > $tmp_file/index.html | ||
pod_name="pv-pod" | ||
# Define temporary file at yaml | ||
sed -i "s|tmp_data|${tmp_file}|g" ${pod_config_dir}/pv-volume.yaml | ||
} | ||
|
||
@test "Create Persistent Volume" { | ||
volume_name="pv-volume" | ||
volume_claim="pv-claim" | ||
|
||
# Create the persistent volume | ||
sudo -E kubectl create -f "${pod_config_dir}/pv-volume.yaml" | ||
|
||
# Check the persistent volume | ||
sudo -E kubectl get pv $volume_name | grep Available | ||
|
||
# Create the persistent volume claim | ||
sudo -E kubectl create -f "${pod_config_dir}/volume-claim.yaml" | ||
|
||
# Check the persistent volume claim | ||
sudo -E kubectl get pvc $volume_claim | grep Bound | ||
|
||
# Create pod | ||
sudo -E kubectl create -f "${pod_config_dir}/pv-pod.yaml" | ||
|
||
# Check pod creation | ||
sudo -E kubectl wait --for=condition=Ready pod "$pod_name" | ||
|
||
cmd="cat /mnt/index.html" | ||
sudo -E kubectl exec $pod_name -- sh -c "$cmd" | grep "$msg" | ||
} | ||
|
||
teardown() { | ||
sudo -E kubectl delete pod "$pod_name" | ||
sudo 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
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,27 @@ | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: pv-pod | ||
annotations: | ||
io.kubernetes.cri-o.TrustedSandbox: "false" | ||
io.kubernetes.cri.untrusted-workload: "true" | ||
spec: | ||
volumes: | ||
- name: pv-storage | ||
persistentVolumeClaim: | ||
claimName: pv-claim | ||
containers: | ||
- name: pv-container | ||
image: busybox | ||
ports: | ||
command: | ||
- sleep | ||
- "120" | ||
volumeMounts: | ||
- mountPath: "/mnt/" | ||
name: pv-storage |
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
integration/kubernetes/untrusted_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 |