#!/bin/bash
src='env-name1'
dest='env-name2'
echo ${src} ${dest}
dir='/opt/shell/k8s_setimage'
cd ${dir}/list/
su - ${src} -c ${dir}/get_images.sh >${src}.list
su - ${dest} -c ${dir}/get_images.sh >${dest}.list
wc -l ${src}.list
wc -l ${dest}.list
cat ${src}.list|grep -vE "deploy-kie-server|courier-example|eureka-server"|while read line
do
ns=`echo $line|awk -F @ '{print $1}'`
dpm=`echo $line|awk -F @ '{print $2}'|sed 's/-prod$/-record/g'`
cname=`echo $line|awk -F @ '{print $3}'|sed 's/-prod$/-record/g'`
image=`echo $line|awk -F @ '{print $4}'|sed 's/-vpc//g'`
src_ver=`echo $line|awk -F : '{print $NF}'`
if grep -q "@${dpm}@" ${dest}.list; then
dest_ver=`grep "@${dpm}@" ${dest}.list|awk -F : '{print $NF}'`
if [ ${src_ver} != ${dest_ver} ]; then
echo ${ns} ${dpm} ${src_ver} ${dest_ver}
su - ${dest} -c "kubectl -n ${ns} set image deployment/${dpm} ${cname}=${image}"
fi
else
echo =====${ns} ${dpm} not in ${dest}
fi
done
cat ${dest}.list|while read line
do
ns=`echo $line|awk -F @ '{print $1}'`
dpm=`echo $line|awk -F @ '{print $2}'|sed 's/-hwbeta$/-prod/g'`
if grep -q "@${dpm}@" ${src}.list; then
:
else
echo +++++${ns} ${dpm} not in ${src}
fi
done