Skip to content

Commit

Permalink
JSON output format for logs from entrypoint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthvn committed Jun 30, 2020
1 parent abf7fed commit a5446a4
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 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

function log_in_json()
{
FILENAME="${0##*/}"
LOGTYPE=$1
MSG=$2
TIMESTAMP=$(date +%FT%T.%3NZ)
echo '{"level":'"$LOGTYPE"',"ts":'"$TIMESTAMP"',"caller":'"$FILENAME"',"msg":'"$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,6 +70,7 @@ wait_for_ipam() {
# If there is no init container, copy the required files
if [[ "$AWS_VPC_K8S_CNI_CONFIGURE_RPFILTER" != "false" ]]; then
# Copy files
log_in_json info "Copying CNI plugin binaries ... "
PLUGIN_BINS="portmap aws-cni-support.sh"
for b in $PLUGIN_BINS; do
# If the file exist, delete it first
Expand All @@ -71,14 +81,22 @@ if [[ "$AWS_VPC_K8S_CNI_CONFIGURE_RPFILTER" != "false" ]]; then
done
fi

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

log_in_json info "Checking for IPAM connectivity ... "

if ! wait_for_ipam; then
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

log_in_json info "ok. "

log_in_json info "Copying CNI plugin binary and config file ..."

cp aws-cni "$HOST_CNI_BIN_PATH"

sed -i s~__VETHPREFIX__~"${AWS_VPC_K8S_CNI_VETHPREFIX}"~g 10-aws.conflist
Expand All @@ -87,9 +105,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"

log_in_json info "ok. "

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
log_in_json info "Foregrounding IPAM daemon ..."
fg %1 >/dev/null 2>&1 || { echo "failed (process terminated)" && cat "$AGENT_LOG_PATH" && exit 1; }

0 comments on commit a5446a4

Please sign in to comment.