From f396944d1e61dcafc2b073648fbe88a0d1bb8e06 Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Fri, 5 Jul 2024 12:34:09 +0800 Subject: [PATCH] Fix install_cni_chaining not creating CNI conf correctly in some cases The chaining CNI conf was not created correctly under two conditions: 1. If there is non CNI conf file in the directory, like a kubeconfig required by the primary CNI. 2. If the CNI conf file is created but not completely written yet. The patch ensures it only selects valid CNI conf and waits for it to be written before using it to create the chaining CNI conf. Signed-off-by: Quan Tian --- build/images/scripts/install_cni_chaining | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build/images/scripts/install_cni_chaining b/build/images/scripts/install_cni_chaining index f364a8f730a..e981616a902 100755 --- a/build/images/scripts/install_cni_chaining +++ b/build/images/scripts/install_cni_chaining @@ -50,7 +50,8 @@ done # Find the cni conf file with lowest name, which is not installed by us while true; do - cni_conf_name=$(ls "$HOST_CNI_NET_DIR" | grep -v antrea | head -n1) + # CNI conf file must have an extension of ".conflist", "*.conf", or "*.json". + cni_conf_name=$(ls "$HOST_CNI_NET_DIR" | grep -E "\.conflist$|\.conf$|\.json$" | grep -v antrea | head -n1) if [[ ! -z $cni_conf_name ]]; then break fi @@ -69,6 +70,15 @@ cni_conf_sha="" function update_cni_conf { log_info "install_cni_chaining" "updating CNI conf file $cni_conf_name -> $cni_conf_name_antrea" + # The CNI conf file may not have been completely written. + while true; do + if [ -s "$cni_conf_path" ] && jq empty "$cni_conf_path" 2>/dev/null; then + break + fi + log_info "install_cni_chaining" "CNI conf file is empty or invalid. Retrying after 2 secs" + sleep 2s + done + # We use the following steps: # 1. read the input file once and store its contents in a variable # 2. perform the necessary changes on the variable contents