Skip to content

Instantly share code, notes, and snippets.

@timebertt
Last active November 9, 2022 12:01
Show Gist options
  • Save timebertt/371480eca17ba263020052eb3a4687c7 to your computer and use it in GitHub Desktop.
Save timebertt/371480eca17ba263020052eb3a4687c7 to your computer and use it in GitHub Desktop.
List all pulled images in a cluster with their supported platforms

List all pulled images in a cluster with their supported platforms

This script lists all images that are present on any of the cluster's nodes and determines the platforms supported by the image. It uses the crane tool for detecting supported platforms.

Usage

Example usage:

$ ./get-all-image-platforms.sh
Checking docker.io/calico/cni:v3.24.1
=> supports: ["linux/arm","linux/amd64","linux/arm64","linux/ppc64le"]
Checking docker.io/calico/kube-controllers:v3.24.1
=> supports: ["linux/arm","linux/amd64","linux/arm64","linux/ppc64le"]
[
  {
    "image": "docker.io/calico/cni:v3.24.1",
    "platforms": [
      "linux/arm",
      "linux/amd64",
      "linux/arm64",
      "linux/ppc64le"
    ]
  },
  {
    "image": "docker.io/calico/kube-controllers:v3.24.1",
    "platforms": [
      "linux/arm",
      "linux/amd64",
      "linux/arm64",
      "linux/ppc64le"
    ]
  }
]

Save to a file for further analysis:

$ ./get-all-image-platforms.sh > /tmp/images.json
Checking docker.io/calico/cni:v3.24.1
=> supports: ["linux/arm","linux/amd64","linux/arm64","linux/ppc64le"]
Checking docker.io/calico/kube-controllers:v3.24.1
=> supports: ["linux/arm","linux/amd64","linux/arm64","linux/ppc64le"]
...

Find all images that don't support linux/arm64 yet:

$ cat /tmp/images.json | jq -r '. - map(select(.platforms[] | contains("linux/arm64"))) | .[].image'
gcr.io/istio-release/pilot:1.14.1-distroless
gcr.io/istio-release/proxyv2:1.14.1-distroless
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
if ! which crane &>/dev/null ; then
>&2 echo "crane is not installed; install it from https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md"
exit 1
fi
images="[]"
while IFS= read -r image; do
>&2 echo "Checking $image"
if ! platforms="$(crane manifest "$image" | jq -c '[ .manifests[].platform | "\(.os)/\(.architecture)" ]' 2>/dev/null)" ; then
# not a multi-arch manifest, get the config to determine platform
platforms=$(crane config "$image" | jq -c '[ "\(.os)/\(.architecture)" ]')
fi
>&2 echo "=> supports: $platforms"
images="$(echo "$images" | jq '. += [{"image": "'"$image"'", "platforms": '"$platforms"'}]')"
done < <(kubectl get no -ojson | jq -r '.items[].status.images[].names[-1]' | sort | uniq)
echo "$images" | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment