Skip to content

Commit

Permalink
rthooks: move rt detection in a helpers file
Browse files Browse the repository at this point in the history
Create an helpers file for scripts and add a function for detecting the
runtime system there. This is meant to be used by a script added in a
subsequent patch.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Aug 7, 2024
1 parent 143e15f commit 9392e12
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
29 changes: 29 additions & 0 deletions contrib/tetragon-rthooks/scripts/helpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# vim:set noet ci pi ts=4 sw=4 ft=bash

detect_runtime() {
crictlcmd=$(minikube ssh -- 'sudo crictl version | sed -ne "s/RuntimeName:[[:space:]]\+\(.*\)/\1/p"')
if [[ "$crictlcmd" =~ "containerd" ]]; then
echo "containerd"
return 0
fi
if [[ "$crictlcmd" =~ "cri-o" ]]; then
echo "crio"
return 0
fi

kubeletcmd=$(minikube ssh -- 'sudo tr \\0 " " < /proc/"$(pgrep kubelet)"/cmdline')
if [[ "$kubeletcmd" =~ "containerd.sock" ]]; then
echo "containerd"
return 0
fi

if [[ "$kubeletcmd" =~ "crio.sock" ]]; then
echo "crio"
return 0
fi

echo 1>&2 "Unknown runtime, bailing out"
echo 1>&2 "crictlcmd output: $crictlcmd"
echo 1>&2 "kubeletcmd output: $kubeletcmd"
exit 1
}
39 changes: 14 additions & 25 deletions contrib/tetragon-rthooks/scripts/minikube-install-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ HOOKDIR=$(dirname $HOOKNAME)
BASEHOOKNAME=$(basename $HOOKNAME)
LOCALHOOK="$RTHOOKSPATH/$BASEHOOKNAME"

source ${SCRIPTPATH}/helpers

usage() {
echo "Usage: $0 [-l|--log] [-d|--debug] [-k|--keep-tmpdir]"
echo " -l|--log: configure hook to just log and not attempt to contact the agent"
Expand Down Expand Up @@ -61,6 +63,8 @@ while [[ $# -gt 0 ]]; do
esac
done

runtime=$(detect_runtime)

xdir=$(mktemp -d /tmp/minikube-tetragon-oci-hook-XXXXXX)
echo "temporary directory: $xdir"
if [ ! "$keep_tmpdir" == "1" ]; then
Expand Down Expand Up @@ -125,31 +129,16 @@ install_crio() {
minikube cp $xdir/hook.json /usr/share/containers/oci/hooks.d/teragon-oci-hook.json
}

crictlcmd=$(minikube ssh -- 'sudo crictl version | sed -ne "s/RuntimeName:[[:space:]]\+\(.*\)/\1/p"')
if [[ "$crictlcmd" =~ "containerd" ]]; then
install_containerd
exit 0
fi
if [[ "$crictlcmd" =~ "crio.sock" ]]; then
install_crio
exit 0
fi

kubeletcmd=$(minikube ssh -- 'sudo tr \\0 " " < /proc/"$(pgrep kubelet)"/cmdline')
if [[ "$kubeletcmd" =~ "containerd.sock" ]]; then
case $runtime in
containerd)
install_containerd
exit 0
fi

if [[ "$kubeletcmd" =~ "crio.sock" ]]; then
;;
crio)
install_crio
exit 0
fi


set +x
echo "Unknown runtime, bailing out"
echo "crictlcmd: $crictlcmd"
echo "kubeletcmd: $kubeletcmd"
exit 1

;;
*)
echo "Unknown runtime"
exit 1
;;
esac

0 comments on commit 9392e12

Please sign in to comment.