From 79fd64ac965715ab399fa27a416a43862fe5cb99 Mon Sep 17 00:00:00 2001 From: Claes Mogren Date: Wed, 31 Jul 2019 15:43:09 -0700 Subject: [PATCH] Update start script to wait for ipamd health Wait for the ipamd health check to be SERVING before copying in the CNI binary and config file. #282 --- scripts/install-aws.sh | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/scripts/install-aws.sh b/scripts/install-aws.sh index 5814284a4a..e031a99220 100755 --- a/scripts/install-aws.sh +++ b/scripts/install-aws.sh @@ -1,14 +1,42 @@ #!/usr/bin/env bash -echo "===== Starting installing AWS-CNI =========" -sed -i s/__VETHPREFIX__/${AWS_VPC_K8S_CNI_VETHPREFIX:-"eni"}/g /app/10-aws.conflist -cp /app/aws-cni /host/opt/cni/bin/ -cp /app/portmap /host/opt/cni/bin/ -cp /app/aws-cni-support.sh /host/opt/cni/bin/ -cp /app/10-aws.conflist /host/etc/cni/net.d/ - -if [[ -f /host/etc/cni/net.d/aws.conf ]]; then + +grpcHealthCheck () { + /app/grpc_health_probe -addr 127.0.0.1:50051 +} + +waitIPamDServing () { + until grpcHealthCheck; do + echo "Waiting for ipamd health check"; + sleep 1; + done +} + +main () { + # Remove old config files that might have been baked into older AMIs + if [[ -f /host/etc/cni/net.d/aws.conf ]]; then rm /host/etc/cni/net.d/aws.conf -fi + fi + + # Copy standard files + cp /app/aws-cni-support.sh /host/opt/cni/bin/ + cp /app/portmap /host/opt/cni/bin/ + + echo "===== Starting amazon-k8s-agent ===========" + /app/aws-k8s-agent & + + # Check ipamd health + echo "Checking if ipamd is serving" + waitIPamDServing + + echo "===== Copying AWS CNI plugin and config =========" + sed -i s/__VETHPREFIX__/"${AWS_VPC_K8S_CNI_VETHPREFIX:-"eni"}"/g /app/10-aws.conflist + cp /app/aws-cni /host/opt/cni/bin/ + cp /app/10-aws.conflist /host/etc/cni/net.d/ + + # Check that ipamd is healthy, exit if the check fails + while grpcHealthCheck; do + sleep 10; + done +} -echo "===== Starting amazon-k8s-agent ===========" -/app/aws-k8s-agent +main