Skip to content

Instantly share code, notes, and snippets.

@jparrill
Last active September 21, 2023 20:49
Show Gist options
  • Save jparrill/982d6de97f1f1418eb563fc9943f2e7f to your computer and use it in GitHub Desktop.
Save jparrill/982d6de97f1f1418eb563fc9943f2e7f to your computer and use it in GitHub Desktop.
Mirror all the missing images which are in `ImagePullBackOff` state in the cluster.
#!/bin/bash
function identifyImages() {
export KUBECONFIG=/root/.kcli/clusters/hub-ipv6/auth/kubeconfig
> imagesToMirror.txt
IFS=$'\n'
for image in $(oc get pod -A -o yaml | grep "Back-off pulling image"); do
extractedImage=$(echo "$image" | grep -o '"[^"]*"')
finalImage=$(echo "$extractedImage" | cut -d '"' -f 2)
echo $finalImage >> $filename
done
}
filename="imagesToMirror.txt"
identifyImages
if [ ! -f "$filename" ]; then
echo "The file '$filename' does not exists"
exit 1
fi
while IFS= read -r line; do
echo "-----> Image: $line"
skopeo copy --all docker://${line} docker://${REGISTRY}/${line#*/}
echo "-----> Copied!"
done < "$filename"
@jparrill
Copy link
Author

This script needs only the KUBECONFIG of the Disconnected openshift cluster and the skopeo tool.
It will mirror all the missing images that the cluster is trying to raise up and it couldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment