flannel-manifests/fromNativeToRegistry.sh

54 lines
1.2 KiB
Bash
Executable File

function FlannelNameToAlt() {
image=$1
tag=$2
ifs=$IFS
IFS=:
set -- $image
image=$1
if [ -z "$tag" ]
then
tag=$2
fi
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
tag=$3
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 $tag)"
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 $tag)"
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
tag=$4
kubeflannelYMLToALT $registry $file $tag