Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions OCI-hook/hookscript.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ set -x

PROC_DIR="${PROC_DIR:-/proc}"

STATE=$(cat)

CG_PATH=$(jq -er '.linux.cgroupsPath' < config.json)
if [[ ! "$CG_PATH" =~ .*"burst".* ]]; then
exit 0
fi

PID=$(jq -er '.pid' < status)
CONTAINERID=$(jq -er '.linux.cgroupsPath | split(":")[2]' < config.json)
rc=$({{ .RuntimeCmd }})
PID=$(echo "$STATE" | jq -er '.pid')
if [ -z "$PID" ]; then
exit 0
fi
CONTAINERID=$(echo "$STATE" | jq -er '.id')
{{ .RuntimeCmd }}
rc=$?
if [ "$rc" -eq 0 ]; then
exit 0
fi
Expand Down
1 change: 0 additions & 1 deletion OCI-hook/testData/bin/crun-fail/crun
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/bash
echo "1"
exit 1
1 change: 0 additions & 1 deletion OCI-hook/testData/bin/crun-success/crun
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/bash
echo "0"
exit 0
9 changes: 8 additions & 1 deletion OCI-hook/testData/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ for scenario_dir in "${SCENARIOS_DIR}"/*/; do
echo "--- ${scenario}"
echo " crun: ${use_crun}, expected exit: ${expected_exit_code}, PROC_DIR: ${proc_dir}"

state_file="${scenario_dir}/state.json"
if [ -f "${state_file}" ]; then
state_input="${state_file}"
else
state_input="/dev/null"
fi

set +e
(
cd "${scenario_dir}"
PATH="${crun_bin_dir}:${PATH}" PROC_DIR="${proc_dir}" "${RENDERED_SCRIPT}"
PATH="${crun_bin_dir}:${PATH}" PROC_DIR="${proc_dir}" "${RENDERED_SCRIPT}" < "${state_input}"
) > /dev/null 2>&1
actual_exit_code=$?
set -e
Expand Down
1 change: 1 addition & 0 deletions OCI-hook/testData/scenarios/01-non-burstable/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ociVersion":"1.0","id":"container123","pid":12345,"root":"/var/lib/containers/rootfs","bundle":"/run/containers/bundle","status":"running"}
3 changes: 0 additions & 3 deletions OCI-hook/testData/scenarios/01-non-burstable/status

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ociVersion":"1.0","id":"container456","pid":12345,"root":"/var/lib/containers/rootfs","bundle":"/run/containers/bundle","status":"running"}
3 changes: 0 additions & 3 deletions OCI-hook/testData/scenarios/02-burstable-crun-success/status

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ociVersion":"1.0","id":"container789","pid":99999,"root":"/var/lib/containers/rootfs","bundle":"/run/containers/bundle","status":"running"}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ociVersion":"1.0","id":"container321","pid":12345,"root":"/var/lib/containers/rootfs","bundle":"/run/containers/bundle","status":"running"}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ociVersion":"1.0","id":"container654","pid":12345,"root":"/var/lib/containers/rootfs","bundle":"/run/containers/bundle","status":"running"}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"linux": {
"cgroupsPath": "kubepods:burstable:container999"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success
4 changes: 2 additions & 2 deletions pkg/wasp/oci-hook-render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (r *Renderer) Render() error {

switch r.runtimeCmd {
case RuncBinary:
data.RuntimeCmd = fmt.Sprintf("%s update \"$CONTAINERID\" --memory-swap -1\n", RuncBinary)
data.RuntimeCmd = fmt.Sprintf("%s update \"$CONTAINERID\" --memory-swap -1", RuncBinary)
case CrunBinary:
data.RuntimeCmd = fmt.Sprintf("%s update --memory-swap=-1 \"$CONTAINERID\"\n", CrunBinary)
data.RuntimeCmd = fmt.Sprintf("%s update --memory-swap=-1 \"$CONTAINERID\"", CrunBinary)
default:
return fmt.Errorf("unsupported OCI runtime %s", r.runtimeCmd)
}
Expand Down
Loading