-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathverify-image-digests.sh
More file actions
executable file
·50 lines (44 loc) · 2.08 KB
/
Copy pathverify-image-digests.sh
File metadata and controls
executable file
·50 lines (44 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Copyright 2025 The Kubernetes Authors.
#
# 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.
# example usage:
# ./verify-image-digests.sh 'v1.33.*' registry.k8s.io/images/k8s-staging-provider-os/images.yaml
# default to match all images
MATCH=${1:-'.*'}
# fail if $2 is not set
YAML_FILE=${2:?Usage: $0 '<match>' <yaml_file>}
# fail if file does not exist
if [ ! -f "${YAML_FILE}" ]; then
echo "ERROR: File ${YAML_FILE} does not exist" >&2
exit 1
fi
while read -r IMAGE DIGEST TAG; do
#echo "image=$IMAGE, digest='$DIGEST', tag=$TAG"
digest="$(curl -sI "https://gcr.io/v2/k8s-staging-provider-os/${IMAGE}/manifests/${TAG}" | awk '/(i?)docker-content-digest/{ gsub(/\r/, ""); print tolower($NF)}')"
if [ -z "$digest" ]; then
echo "ERROR: gcr.io/k8s-staging-provider-os/$IMAGE:$TAG digest is empty" >&2
continue
fi
if [ "$digest" != "$DIGEST" ]; then
echo "ERROR: gcr.io/k8s-staging-provider-os/$IMAGE:$TAG digest mismatch: expected $DIGEST, got $digest" >&2
fi
digest1="$(curl -sIL "https://registry.k8s.io/v2/provider-os/${IMAGE}/manifests/${TAG}" | awk '/(i?)docker-content-digest/{ gsub(/\r/, ""); print tolower($NF)}')"
if [ -z "$digest1" ]; then
echo "ERROR: registry.k8s.io/provider-os/$IMAGE:$TAG digest is empty" >&2
continue
fi
if [ "$digest1" != "$DIGEST" ]; then
echo "ERROR: registry.k8s.io/provider-os/$IMAGE:$TAG digest mismatch: expected $DIGEST, got $digest1" >&2
fi
done <<< $(yq '.[] | .name as $name | .dmap | to_entries | sort_by(.value[0]) | reverse | .[] | select(.value[0] | test("'"${MATCH}"'")) | "\($name) \(.key) \(.value[0])"' "${YAML_FILE}")