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

JSON output format for the entrypoint script #1066

Merged
merged 1 commit into from
Jul 1, 2020
Merged
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
33 changes: 19 additions & 14 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ set -eu
# turn on bash's job control
set -m

log_in_json()
{
FILENAME="${0##*/}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't seen "${0##*/}" before 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From stack overflow - "for the variable $0, and the pattern '/', the two hashes mean from the beginning of the parameter, delete the longest (or greedy) match—up to and including the pattern. So, where $0 is the name of a file, eg., $HOME/documents/doc.txt, then the parameter would be expanded as: doc.txt" :D

LOGTYPE=$1
MSG=$2
TIMESTAMP=$(date +%FT%T.%3NZ)
printf '{"level":"%s","ts":"%s","caller":"%s","msg":"%s"}\n' "$LOGTYPE" "$TIMESTAMP" "$FILENAME" "$MSG"
}
jayanthvn marked this conversation as resolved.
Show resolved Hide resolved

# Check for all the required binaries before we go forward
if [ ! -f aws-k8s-agent ]; then
echo "Required aws-k8s-agent executable not found."
log_in_json error "Required aws-k8s-agent executable not found."
exit 1
fi
if [ ! -f grpc-health-probe ]; then
echo "Required grpc-health-probe executable not found."
log_in_json error "Required grpc-health-probe executable not found."
exit 1
fi

Expand Down Expand Up @@ -61,30 +70,26 @@ wait_for_ipam() {
# If there is no init container, copy the required files
if [[ "$AWS_VPC_K8S_CNI_CONFIGURE_RPFILTER" != "false" ]]; then
# Copy files
echo "Copying CNI plugin binaries ... "
log_in_json info "Copying CNI plugin binaries ... "
PLUGIN_BINS="loopback portmap bandwidth aws-cni-support.sh"
for b in $PLUGIN_BINS; do
# Install the binary
install "$b" "$HOST_CNI_BIN_PATH"
done
fi

echo -n "Starting IPAM daemon in the background ... "
log_in_json info "Starting IPAM daemon in the background ... "
./aws-k8s-agent | tee -i "$AGENT_LOG_PATH" 2>&1 &
echo "ok."

echo -n "Checking for IPAM connectivity ... "
log_in_json info "Checking for IPAM connectivity ... "

if ! wait_for_ipam; then
echo " failed."
echo "Timed out waiting for IPAM daemon to start:"
log_in_json error "Timed out waiting for IPAM daemon to start:"
cat "$AGENT_LOG_PATH" >&2
exit 1
fi

echo "ok."

echo -n "Copying CNI plugin binary and config file ... "
log_in_json info "Copying CNI plugin binary and config file ... "

install aws-cni "$HOST_CNI_BIN_PATH"

Expand All @@ -94,12 +99,12 @@ sed -i s~__PLUGINLOGFILE__~"${AWS_VPC_K8S_PLUGIN_LOG_FILE}"~g 10-aws.conflist
sed -i s~__PLUGINLOGLEVEL__~"${AWS_VPC_K8S_PLUGIN_LOG_LEVEL}"~g 10-aws.conflist
cp 10-aws.conflist "$HOST_CNI_CONFDIR_PATH"

echo "ok."
log_in_json info "Successfully copied CNI plugin binary and config file."

if [[ -f "$HOST_CNI_CONFDIR_PATH/aws.conf" ]]; then
rm "$HOST_CNI_CONFDIR_PATH/aws.conf"
fi

# Bring the aws-k8s-agent process back into the foreground
echo "Foregrounding IPAM daemon ... "
fg %1 >/dev/null 2>&1 || { echo "failed (process terminated)" && cat "$AGENT_LOG_PATH" && exit 1; }
log_in_json info "Foregrounding IPAM daemon ..."
fg %1 >/dev/null 2>&1 || { log_in_json error "failed (process terminated)" && cat "$AGENT_LOG_PATH" && exit 1; }