Last active
July 25, 2023 20:43
-
-
Save IAKAT/29d2f174d04270f1034a8efd528c6ceb to your computer and use it in GitHub Desktop.
kubernetes check if all images have arm64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2023 kat | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# Depends on https://github.com/containers/skopeo | |
# Example usage: | |
# k get pod -o yaml | grep image: | sed 's/.*image: //' | sort | uniq | xargs -P50 bash isitarm64imageready.sh | |
image=$1 | |
if [[ $image != *"/"* ]]; then | |
image="docker.io/library/$image" | |
fi | |
# Remove @sha256:... from image name | |
image=$(echo $image | cut -d'@' -f1) | |
# check if image has arm64 and amd64 | |
# For each command, save output and exit code. | |
# If exit code is 0, then the command succeeded. | |
# If exit code is non-zero, then the image does not have the architecture. | |
# arm64 | |
ARM64_OUTPUT=$(skopeo inspect docker://$image --override-os=linux --override-arch=arm64 2>/dev/null) | |
ARM64_EXIT_CODE=$? | |
if [ $ARM64_EXIT_CODE -ne 0 ]; then | |
echo "ERROR: $image does not have arm64" | |
# elif check if the image .Architecture is arm64 | |
elif [[ $(echo $ARM64_OUTPUT | jq -r '.Architecture') != "arm64" ]]; then | |
echo "ERROR: $image does not have arm64" | |
fi | |
# amd64 | |
AMD64_OUTPUT=$(skopeo inspect docker://$image --override-os=linux --override-arch=amd64 2>/dev/null) | |
AMD64_EXIT_CODE=$? | |
if [ $AMD64_EXIT_CODE -ne 0 ]; then | |
echo "ERROR: $image does not have amd64" | |
# elif check if the image .Architecture is amd64 | |
elif [[ $(echo $AMD64_OUTPUT | jq -r '.Architecture') != "amd64" ]]; then | |
echo "ERROR: $image does not have amd64" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment