dev scripts: update lm-update.sh and update-image-pull-policy.sh

To include a way to restart every Longhorn components automatically with
the latest image.

1. Now `lm-update.sh` will set `imagePullPolicy: Always` for the manager
and the driver.
2. Now update-image-pull-policy.sh will update the `imagePullPolicy` for
all the running deployments and daemonsets in the `longhorn-system`
namespace, including CSI components.

Signed-off-by: Sheng Yang <sheng.yang@rancher.com>
This commit is contained in:
Sheng Yang 2020-10-19 11:57:29 -07:00 committed by Sheng Yang
parent 0a5fa0867e
commit 3870716b8c
2 changed files with 19 additions and 28 deletions

View File

@ -29,8 +29,10 @@ docker push ${private}
escaped_private=${private//\//\\\/} escaped_private=${private//\//\\\/}
sed -i "s/image\:\ .*\/${project}:.*/image\:\ ${escaped_private}/g" $yaml sed -i "s/image\:\ .*\/${project}:.*/image\:\ ${escaped_private}/g" $yaml
sed -i "s/-\ .*\/${project}:.*/-\ ${escaped_private}/g" $yaml sed -i "s/-\ .*\/${project}:.*/-\ ${escaped_private}/g" $yaml
sed -i "s/imagePullPolicy\:\ .*/imagePullPolicy\:\ Always/g" $yaml
sed -i "s/image\:\ .*\/${project}:.*/image\:\ ${escaped_private}/g" $driver_yaml sed -i "s/image\:\ .*\/${project}:.*/image\:\ ${escaped_private}/g" $driver_yaml
sed -i "s/-\ .*\/${project}:.*/-\ ${escaped_private}/g" $driver_yaml sed -i "s/-\ .*\/${project}:.*/-\ ${escaped_private}/g" $driver_yaml
sed -i "s/imagePullPolicy\:\ .*/imagePullPolicy\:\ Always/g" $driver_yaml
set +e set +e

View File

@ -1,35 +1,24 @@
echo "Update imagePullPolicy to be Always for manager, UI, driver deployer, engine image" #!/bin/bash
# Update imagePullPolicy for Longhorn manager daemonset NS=longhorn-system
kubectl patch daemonset longhorn-manager -n longhorn-system -p \ KINDS="daemonset deployments"
'{"spec":{"template":{"spec":{"containers":[{"name":"longhorn-manager", "imagePullPolicy":"Always"}]}}}}'
sleep 5
# Update imagePullPolicy for Longhorn UI deployment function patch_kind {
kubectl patch deployment longhorn-ui -n longhorn-system -p \ kind=$1
'{"spec":{"template":{"spec":{"containers":[{"name":"longhorn-ui", "imagePullPolicy":"Always"}]}}}}' list=$(kubectl -n $NS get $kind -o name)
sleep 5 for obj in $list
# Update imagePullPolicy for Longhorn Driver Deployer deployment
kubectl patch deployment longhorn-driver-deployer -n longhorn-system -p \
'{"spec":{"template":{"spec":{"containers":[{"name":"longhorn-driver-deployer", "imagePullPolicy":"Always"}]}}}}'
sleep 1
echo "wait 15s to make sure that the updated longhorn manager pods come up ..."
sleep 15
# Update all imagePullPolicy for Longhorn Engine Image Daemonsets
temp_file='./.engine-image-daemon-list'
kubectl get daemonsets -n longhorn-system | grep -oE "engine-image-ei-.{8}" > ${temp_file}
while IFS= read -r line
do do
kubectl patch daemonset ${line} -n longhorn-system -p \ echo Updating $obj to imagePullPolicy: Always
"{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"${line}\", \"imagePullPolicy\":\"Always\"}]}}}}" name=${obj##*/}
sleep 5 kubectl -n $NS patch $obj -p '{"spec": {"template": {"spec":{"containers":[{"name":"'$name'","imagePullPolicy":"Always"}]}}}}'
done < ${temp_file} done
}
rm ${temp_file} for kind in $KINDS
do
patch_kind $kind
done
echo "Warning: Make sure check and wait for all pods running again!" echo "Warning: Make sure check and wait for all pods running again!"
echo "Current status: (Ctl+c to exit)" echo "Current status: (CTRL-C to exit)"
kubectl get pods -w -n longhorn-system kubectl get pods -w -n longhorn-system