Skip to content

Commit

Permalink
Optionally avoid sleeping in entrypoint.sh
Browse files Browse the repository at this point in the history
Container image might be used as `initcontainers` in kubernetes Pods. In
such scenarios, it's important for the image entrypoint to exits once the
copy logic is completed. Otherwise, the pod would stuck in a `PodInitializing`
phase.

Add Makefile rule `image-test` to check the integrity of the entrypoint.sh script.

https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Jan 11, 2024
1 parent 07ecbf9 commit 27b7dc8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ fmt: ; $(info Running gofmt...) @ ## Run gofmt on all source files
image: | $(BASE) ; $(info Building Docker image...) @ ## Build SR-IOV CNI docker image
@$(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(DOCKERARGS)

image-test: image
$Q $(BASE)/images/image_test.sh $(IMAGE_BUILDER) $(TAG)

# Misc

.PHONY: deps-update
Expand Down
9 changes: 9 additions & 0 deletions images/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
# Set known directories.
CNI_BIN_DIR="/host/opt/cni/bin"
SRIOV_BIN_FILE="/usr/bin/sriov"
AVOID_SLEEP=0

# Give help text for parameters.
usage()
Expand All @@ -18,6 +19,7 @@ usage()
printf "\t-h --help\n"
printf "\t--cni-bin-dir=%s\n" "$CNI_BIN_DIR"
printf "\t--sriov-bin-file=%s\n" "$SRIOV_BIN_FILE"
printf "\t--avoid-sleep\n"
}

# Parse parameters given as arguments to this script.
Expand All @@ -35,6 +37,9 @@ while [ "$1" != "" ]; do
--sriov-bin-file)
SRIOV_BIN_FILE=$VALUE
;;
--avoid-sleep)
AVOID_SLEEP=1
;;
*)
/bin/echo "ERROR: unknown parameter \"$PARAM\""
usage
Expand All @@ -57,6 +62,10 @@ done
# Copy file into proper place.
cp -f "$SRIOV_BIN_FILE" "$CNI_BIN_DIR"

if [ $AVOID_SLEEP -eq 1 ]; then
exit 0
fi

echo "Entering sleep... (success)"
trap : TERM INT

Expand Down
22 changes: 22 additions & 0 deletions images/image_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -x

OCI_RUNTIME=$1
IMAGE_UNDER_TEST=$2

OUTPUT_DIR=`mktemp -d`

${OCI_RUNTIME} run -v ${OUTPUT_DIR}:/out ${IMAGE_UNDER_TEST} --cni-bin-dir=/out --avoid-sleep

if [ ! -e "${OUTPUT_DIR}/sriov" ]; then
echo "Output file ${OUTPUT_DIR}/sriov not found"
exit 1
fi

if [ ! -s "${OUTPUT_DIR}/sriov" ]; then
echo "Output file ${OUTPUT_DIR}/sriov is empty"
exit 1
fi

exit 0

0 comments on commit 27b7dc8

Please sign in to comment.