diff --git a/scripts/restore-stuck-updates.sh b/scripts/restore-stuck-updates.sh index f387d41b73919dcc3b9d98d74a69bf0e5cf0a61a..3c6cd4c97622277ecb81e7cd8b9c3e3130874ece 100755 --- a/scripts/restore-stuck-updates.sh +++ b/scripts/restore-stuck-updates.sh @@ -1,3 +1,27 @@ #!/bin/sh -oc get -o json drupalsite -A | jq -r '.items[] | select(.status.releaseID.current != .status.releaseID.failsafe)|"\(.metadata.name) \(.metadata.namespace) \(.status.releaseID.failsafe)"'| xargs -l bash -c 'export name=$(echo $2 | cut -d"-" -f -2); export spec=$(echo $2 |cut -d"-" -f 3"-"45); echo "[{\"op\": \"replace\",\"path\":\"/spec/version/name\",\"value\":\"${name}\"}, {\"op\":\"replace\",\"path\":\"/spec/version/releaseSpec\",\"value\":\"${spec}\"}]">patchs; oc patch drupalsite/$0 -n $1 --type json --patch-file patchs; sleep 1s' +### FILTERs +STUCK_WEBSITE_FILTER='.status.releaseID.current != .status.releaseID.failsafe' +WEBSITE_LIST_OUTPUT='(.metadata.name + " " + .metadata.namespace + " " + .status.releaseID.failsafe)' + +# Time between patches not to overwhelm the Operator +# This can be skipped/reduced once we have this issue closed: https://gitlab.cern.ch/webservices/webframeworks-planning/-/issues/869 +export GRACE_PERIOD="1s" + +## NB: This will match the spec of all websites based on failStatus version +## +oc get -o json drupalsite -A | + jq -r ".items[] | select(${STUCK_WEBSITE_FILTER}) | ${WEBSITE_LIST_OUTPUT}" | + # Retrieve Spec Name from failSafe status + xargs -l bash -c 'export name=$(echo $2 | cut -d"-" -f -2); + # Retrieve spec ReleaseID from failsafe status + export spec=$(echo $2 |cut -d"-" -f 3"-"45); + # Generate Patch to be applied + cat > patch.yaml <<EOF +spec: + version: + name: ${name} + releaseSpec: ${spec} +EOF + oc patch drupalsite/$0 -n $1 --type=merge --patch-file patch.yaml; + sleep ${GRACE_PERIOD}'