From f0a43ca0a553b2208b0d4ec0e11da6332d88efb5 Mon Sep 17 00:00:00 2001 From: Doug Smith Date: Thu, 28 Feb 2019 13:56:08 -0500 Subject: [PATCH] Adds wait loop to entrypoint when --multus-conf-file=auto (#234) * [entrypoint] Adds wait loop when using --multus-conf-file=auto waits for presence of any conf file * [entrypoint] fixes incorrect logical comparison * [entrypoint] add log every 5 tries, fix tries increment, fix logical comparison * [entrypoint] fix attempt output --- images/entrypoint.sh | 55 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/images/entrypoint.sh b/images/entrypoint.sh index 4b874f1eb..8457c087e 100755 --- a/images/entrypoint.sh +++ b/images/entrypoint.sh @@ -157,30 +157,39 @@ fi if [ "$MULTUS_CONF_FILE" == "auto" ]; then echo "Generating Multus configuration file ..." - MASTER_PLUGIN="$(ls $CNI_CONF_DIR | grep -E '\.conf(list)?$' | grep -Ev '00-multus\.conf' | head -1)" - if [ "$MASTER_PLUGIN" == "" ]; then - echo "Error: Multus could not be configured: no master plugin was found." - exit 1; - else - ISOLATION_STRING="" - if [ "$MULTUS_NAMESPACE_ISOLATION" == true ]; then - ISOLATION_STRING="\"namespaceIsolation\": true," + found_master=false + tries=0 + while [ $found_master == false ]; do + MASTER_PLUGIN="$(ls $CNI_CONF_DIR | grep -E '\.conf(list)?$' | grep -Ev '00-multus\.conf' | head -1)" + if [ "$MASTER_PLUGIN" == "" ]; then + if [ $tries -lt 600 ]; then + if ! (($tries % 5)); then + echo "Attemping to find master plugin configuration, attempt $tries" + fi + let "tries+=1" + sleep 1; + else + echo "Error: Multus could not be configured: no master plugin was found." + exit 1; + fi + else + found_master=true + MASTER_PLUGIN_JSON="$(cat $CNI_CONF_DIR/$MASTER_PLUGIN)" + CONF=$(cat <<-EOF +{ + "name": "multus-cni-network", + "type": "multus", + "kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST", + "delegates": [ + $MASTER_PLUGIN_JSON + ] +} +EOF + ) + echo $CONF > $CNI_CONF_DIR/00-multus.conf + echo "Config file created @ $CNI_CONF_DIR/00-multus.conf" fi - MASTER_PLUGIN_JSON="$(cat $CNI_CONF_DIR/$MASTER_PLUGIN)" - CONF=$(cat <<-EOF - { - "name": "multus-cni-network", - "type": "multus", - $ISOLATION_STRING - "kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST", - "delegates": [ - $MASTER_PLUGIN_JSON - ] - } - EOF - ) - echo $CONF > $CNI_CONF_DIR/00-multus.conf - fi + done fi # ---------------------- end Generate "00-multus.conf".