function FlannelNameToAlt() { image=$1 ifs=$IFS IFS=: set -- $image image=$1 tag=$2 if [[ $1 =~ "flannel-cni-plugin" ]] then echo "$U7S_PLATFORM/flannel-cni-plugin:$tag" else echo "$U7S_PLATFORM/flannel:$tag" fi } function kubeflannelYMLToALT() { registry=$1 kubeFlannelFile=$2 initCount=$(cat $kubeFlannelFile | yq -y 'select(.kind=="DaemonSet").spec.template.spec.initContainers' | yq 'length') q='.' i=0 while [ $i -lt $initCount ] do image=$(cat $kubeFlannelFile | yq -y 'select(.kind=="DaemonSet").spec.template.spec.initContainers['$i']' | yq -r '.image') altImage="$registry/$(FlannelNameToAlt $image)" q+='| select(.kind=="DaemonSet").spec.template.spec.initContainers['$i'].image="'$altImage'"' let i=$i+1 done image=$(cat $kubeFlannelFile | yq -y 'select(.kind=="DaemonSet").spec.template.spec.containers[0]' | yq -r '.image') altImage="$registry/$(FlannelNameToAlt $image)" q+='| select(.kind=="DaemonSet").spec.template.spec.containers[0].image="'$altImage'"' yq -y "$q" $kubeFlannelFile } #MAIN registry=$1 export U7S_PLATFORM="k8s-$2" file=$3 kubeflannelYMLToALT $registry $file