execsync: rewrite to fix a bug in conmon

conmon has many flags that are parsed when it's executed, one of them
is "-c". During PR #510 where we vendor latest kube master code,
upstream has changed a test to call a "ctr execsync" with a command of
"sh -c commmand ...".
Turns out:

a) conmon has a "-c" flag which refers to the container name/id
b) the exec command has a "-c" flags but it's for "sh"

That leads to conmon parsing the second "-c" flags from the exec
command causing an error. The executed command looks like:

conmon -c [..other flags..] CONTAINERID -e sh -c echo hello world

This patch rewrites the exec sync code to not pass down to conmon the
exec command via command line. Rather, we're now creating an OCI runtime
process spec in a temp file, pass _the path_ down to conmon, and have
runc exec the command using "runc exec --process
/path/to/process-spec.json CONTAINERID". This is far better in which we
don't need to bother anymore about conflicts with flags in conmon.

Added and fixed some tests also.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-05-25 11:11:14 +02:00
parent 26e90190fc
commit b4251aebd8
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
4 changed files with 93 additions and 25 deletions

View file

@ -401,6 +401,28 @@ function teardown() {
stop_crio
}
@test "ctr execsync conflicting with conmon flags parsing" {
start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
run crioctl ctr create --config "$TESTDATA"/container_redis.json --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run crioctl ctr start --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
run crioctl ctr execsync --id "$ctr_id" sh -c "echo hello world"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "hello world" ]]
cleanup_ctrs
cleanup_pods
stop_crio
}
@test "ctr execsync" {
start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
@ -511,19 +533,22 @@ function teardown() {
run crioctl ctr start --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
run crioctl ctr execsync --id "$ctr_id" "echo hello0 stdout"
run crioctl ctr execsync --id "$ctr_id" echo hello0 stdout
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"$(printf "Stdout:\nhello0 stdout")"* ]]
run crioctl ctr execsync --id "$ctr_id" "echo hello1 stderr >&2"
stderrconfig=$(cat "$TESTDATA"/container_config.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["image"]["image"] = "runcom/stderr-test"; json.dump(obj, sys.stdout)')
echo "$stderrconfig" > "$TESTDIR"/container_config_stderr.json
run crioctl ctr create --config "$TESTDIR"/container_config_stderr.json --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"$(printf "Stderr:\nhello1 stderr")"* ]]
run crioctl ctr execsync --id "$ctr_id" "echo hello2 stderr >&2; echo hello3 stdout"
ctr_id="$output"
run crioctl ctr execsync --id "$ctr_id" stderr
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"$(printf "Stderr:\nhello2 stderr")"* ]]
[[ "$output" == *"$(printf "Stdout:\nhello3 stdout")"* ]]
[[ "$output" == *"$(printf "Stderr:\nthis goes to stderr")"* ]]
run crioctl pod remove --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]