Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally avoid sleeping in entrypoint.sh #83

Merged
merged 1 commit into from
Feb 12, 2024
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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COMMIT?=`git rev-parse --verify HEAD`
LDFLAGS="-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"

# Docker
IMAGE_BUILDER?=@docker
IMAGE_BUILDER?=docker
IMAGEDIR=$(BASE)/images
DOCKERFILE?=$(CURDIR)/Dockerfile
TAG?=k8snetworkplumbingwg/ib-sriov-cni
Expand Down Expand Up @@ -126,13 +126,16 @@ shellcheck: $(BASE) $(SHELLCHECK_TOOL); $(info running shellcheck...) @ ## Run
# Container image
.PHONY: image
image: | $(BASE) ; $(info Building Docker image...) ## Build conatiner image
$(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(IMAGE_BUILD_OPTS)
@$(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(IMAGE_BUILD_OPTS)

# Dependency management
.PHONY: deps-update
deps-update: ; $(info updating dependencies...)
go mod tidy && go mod vendor

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

# Misc

.PHONY: clean
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"
IB_SRIOV_CNI_BIN_FILE="/usr/bin/ib-sriov"
NO_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--ib-sriov-cni-bin-file=%s\n" "$IB_SRIOV_CNI_BIN_FILE"
printf "\t--no-sleep\n"
}

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

if [ $NO_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 --no-sleep

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

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

exit 0
Loading