Add kpod wait
Waits on one or more containers to stop and prints the container's return code Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
parent
214adee0ef
commit
3bf23b684a
12 changed files with 340 additions and 1 deletions
70
test/kpod_wait.bats
Normal file
70
test/kpod_wait.bats
Normal file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load helpers
|
||||
|
||||
IMAGE="redis:alpine"
|
||||
ROOT="$TESTDIR/crio"
|
||||
RUNROOT="$TESTDIR/crio-run"
|
||||
KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}"
|
||||
|
||||
|
||||
# Returns the POD ID
|
||||
function pod_run_from_template(){
|
||||
#1=name, 2=uid, 3=namespace) {
|
||||
NAME=$1 CUID=$2 NAMESPACE=$3 envsubst < ${TESTDATA}/template_sandbox_config.json > ${TESTDIR}/pod-${1}.json
|
||||
crioctl pod run --config ${TESTDIR}/pod-${1}.json
|
||||
}
|
||||
|
||||
# Returns the container ID
|
||||
function container_create_from_template() {
|
||||
#1=name, 2=image, 3=command, 4=id) {
|
||||
NAME=$1 IMAGE=$2 COMMAND=$3 envsubst < ${TESTDATA}/template_container_config.json > ${TESTDIR}/ctr-${1}.json
|
||||
crioctl ctr create --config ${TESTDIR}/ctr-${1}.json --pod "$4"
|
||||
}
|
||||
|
||||
function container_start() {
|
||||
#1=id
|
||||
crioctl ctr start --id "$1"
|
||||
|
||||
}
|
||||
@test "wait on a bogus container" {
|
||||
start_crio
|
||||
run ${KPOD_BINARY} ${KPOD_OPTIONS} wait 12343
|
||||
echo $output
|
||||
[ "$status" -eq 1 ]
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "wait on a stopped container" {
|
||||
run ${KPOD_BINARY} ${KPOD_OPTIONS} pull docker.io/library/busybox:latest
|
||||
echo $output
|
||||
start_crio
|
||||
pod_id=$( pod_run_from_template "test" "test" "test1-1" )
|
||||
echo $pod_id
|
||||
ctr_id=$(container_create_from_template "test-CTR" "docker.io/library/busybox:latest" '["ls"]' "${pod_id}")
|
||||
echo $ctr_id
|
||||
container_start $ctr_id
|
||||
run ${KPOD_BINARY} ${KPOD_OPTIONS} wait $ctr_id
|
||||
[ "$status" -eq 0 ]
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "wait on a sleeping container" {
|
||||
run ${KPOD_BINARY} ${KPOD_OPTIONS} pull docker.io/library/busybox:latest
|
||||
echo $output
|
||||
start_crio
|
||||
pod_id=$( pod_run_from_template "test" "test" "test1-1" )
|
||||
echo $pod_id
|
||||
ctr_id=$(container_create_from_template "test-CTR" "docker.io/library/busybox:latest" '["sleep", "5"]' "${pod_id}")
|
||||
echo $ctr_id
|
||||
run container_start $ctr_id
|
||||
echo $output
|
||||
run ${KPOD_BINARY} ${KPOD_OPTIONS} wait $ctr_id
|
||||
echo $output
|
||||
[ "$status" -eq 0 ]
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
68
test/testdata/template_container_config.json
vendored
Normal file
68
test/testdata/template_container_config.json
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"attempt": 1
|
||||
},
|
||||
"image": {
|
||||
"image": "${IMAGE}"
|
||||
},
|
||||
"command": ${COMMAND},
|
||||
"args": [],
|
||||
"working_dir": "/",
|
||||
"envs": [
|
||||
{
|
||||
"key": "PATH",
|
||||
"value": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
},
|
||||
{
|
||||
"key": "TERM",
|
||||
"value": "xterm"
|
||||
},
|
||||
{
|
||||
"key": "TESTDIR",
|
||||
"value": "test/dir1"
|
||||
},
|
||||
{
|
||||
"key": "TESTFILE",
|
||||
"value": "test/file1"
|
||||
}
|
||||
],
|
||||
"labels": {
|
||||
"type": "small",
|
||||
"batch": "no"
|
||||
},
|
||||
"annotations": {
|
||||
"owner": "dragon",
|
||||
"daemon": "crio"
|
||||
},
|
||||
"privileged": true,
|
||||
"log_path": "",
|
||||
"stdin": false,
|
||||
"stdin_once": false,
|
||||
"tty": false,
|
||||
"linux": {
|
||||
"resources": {
|
||||
"cpu_period": 10000,
|
||||
"cpu_quota": 20000,
|
||||
"cpu_shares": 512,
|
||||
"oom_score_adj": 30
|
||||
},
|
||||
"security_context": {
|
||||
"readonly_rootfs": false,
|
||||
"selinux_options": {
|
||||
"user": "system_u",
|
||||
"role": "system_r",
|
||||
"type": "svirt_lxc_net_t",
|
||||
"level": "s0:c4,c5"
|
||||
},
|
||||
"capabilities": {
|
||||
"add_capabilities": [
|
||||
"setuid",
|
||||
"setgid"
|
||||
],
|
||||
"drop_capabilities": [
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
test/testdata/template_sandbox_config.json
vendored
Normal file
51
test/testdata/template_sandbox_config.json
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"uid": "${CUID}",
|
||||
"namespace": "${NAMESPACE}",
|
||||
"attempt": 1
|
||||
},
|
||||
"hostname": "crioctl_host",
|
||||
"log_directory": "",
|
||||
"dns_config": {
|
||||
"searches": [
|
||||
"8.8.8.8"
|
||||
]
|
||||
},
|
||||
"port_mappings": [],
|
||||
"resources": {
|
||||
"cpu": {
|
||||
"limits": 3,
|
||||
"requests": 2
|
||||
},
|
||||
"memory": {
|
||||
"limits": 50000000,
|
||||
"requests": 2000000
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"group": "test"
|
||||
},
|
||||
"annotations": {
|
||||
"owner": "hmeng",
|
||||
"security.alpha.kubernetes.io/sysctls": "kernel.shm_rmid_forced=1,net.ipv4.ip_local_port_range=1024 65000",
|
||||
"security.alpha.kubernetes.io/unsafe-sysctls": "kernel.msgmax=8192" ,
|
||||
"security.alpha.kubernetes.io/seccomp/pod": "unconfined"
|
||||
},
|
||||
"linux": {
|
||||
"cgroup_parent": "/Burstable/pod_123-456",
|
||||
"security_context": {
|
||||
"namespace_options": {
|
||||
"host_network": false,
|
||||
"host_pid": false,
|
||||
"host_ipc": false
|
||||
},
|
||||
"selinux_options": {
|
||||
"user": "system_u",
|
||||
"role": "system_r",
|
||||
"type": "svirt_lxc_net_t",
|
||||
"level": "s0:c4,c5"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue