Skip to content

Commit

Permalink
Merge pull request clearcontainers#922 from GabyCT/topic/addvolumek8s
Browse files Browse the repository at this point in the history
tests: Add K8s tests for persistent volumes
  • Loading branch information
chavafg authored Dec 3, 2018
2 parents 72919a9 + 72dd8f0 commit c916d9c
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
50 changes: 50 additions & 0 deletions integration/kubernetes/k8s-volume.bats
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
}
1 change: 1 addition & 0 deletions integration/kubernetes/run_kubernetes_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ bats k8s-cpu-ns.bats
bats k8s-memory.bats
bats k8s-liveness-probes.bats
bats k8s-attach-handlers.bats
bats k8s-volume.bats
./cleanup_env.sh
popd
27 changes: 27 additions & 0 deletions integration/kubernetes/untrusted_workloads/pv-pod.yaml
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
19 changes: 19 additions & 0 deletions integration/kubernetes/untrusted_workloads/pv-volume.yaml
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 integration/kubernetes/untrusted_workloads/volume-claim.yaml
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

0 comments on commit c916d9c

Please sign in to comment.