Skip to content

Commit

Permalink
Json o/p for logs from entrypoint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthvn authored and mogren committed Jul 1, 2020
1 parent 2d20308 commit d938e5e
Showing 1 changed file with 19 additions and 14 deletions.
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##*/}"
LOGTYPE=$1
MSG=$2
TIMESTAMP=$(date +%FT%T.%3NZ)
printf '{"level":"%s","ts":"%s","caller":"%s","msg":"%s"}\n' "$LOGTYPE" "$TIMESTAMP" "$FILENAME" "$MSG"
}

# 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; }

0 comments on commit d938e5e

Please sign in to comment.