

export name_space=xxg
export new_tag=5.1.0-24469-111402
export deployment_name=cmii-uav-platform


image_new_name=""
image_name_complete=$(kubectl -n ${name_space} get deployment ${deployment_name} -o=jsonpath='{.spec.template.spec.containers[*].image}')
echo "image_name_complete is => ${image_name_complete}"

if echo "${image_name_complete}" | grep -q "8033"; then
    # 172.28.0.17:8033/cmii/cmii-uav-mission:5.1.0
    image_new_name="$(echo "${image_name_complete}" | cut -d ":" -f1):$(echo "${image_name_complete}" | cut -d ":" -f2):${new_tag}"
else
    # harbor.cdcyy.com.cn/cmii/cmii-uav-platform-seniclive:4.1.0
    image_new_name="$(echo "${image_name_complete}" | cut -d ":" -f1):${new_tag}"
fi


echo "image grep is => ${image_new_name}"

kubectl -n ${name_space} patch deployment ${deployment_name} -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"${deployment_name}\",\"image\": \"${image_new_name}\"}]}}}}"
