Skip to content

Commit 1561b16

Browse files
CORE-11514: Added CI test to check images availability
1 parent 9d1953d commit 1561b16

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ clean:
5050

5151
ci-preflight-checks:
5252
$(MAKE) check-go-mod
53+
$(MAKE) check-images-availability
5354
$(MAKE) verify-go-mods
5455
$(MAKE) check-dockerfiles
5556
$(MAKE) check-language
@@ -71,6 +72,11 @@ go-vet:
7172
check-dockerfiles:
7273
./hack/check-dockerfiles.sh
7374

75+
check-images-availability: bin/yq bin/crane
76+
cd ./hack && \
77+
OPERATOR_VERSION=$(OPERATOR_VERSION) \
78+
./check-images-availability.sh
79+
7480
check-language:
7581
./hack/check-language.sh
7682

hack/check-images-availability.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Resolve script directory
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Use provided YQ or fallback to ../bin/yq (relative to hack/)
8+
YQ="${YQ:-../bin/yq}"
9+
CRANE="${CRANE:-../bin/crane}"
10+
11+
dig gcr.io
12+
curl -I https://gcr.io/v2/
13+
14+
if [ ! -x "$YQ" ]; then
15+
echo "❌ Error: yq not found or not executable at: $YQ" >&2
16+
echo "🔍 Resolved path: $(realpath "$YQ" 2>/dev/null || echo '<unresolvable>')" >&2
17+
exit 1
18+
fi
19+
20+
# Operator version from values.yaml
21+
defaultOperatorVersion=$("$YQ" .tigeraOperator.version < "${SCRIPT_DIR}/../charts/tigera-operator/values.yaml")
22+
OPERATOR_VERSION="${OPERATOR_VERSION:-$defaultOperatorVersion}"
23+
IMAGE_SOURCE="quay.io/tigera/operator:${OPERATOR_VERSION}"
24+
25+
echo "🔍 Checking images for OPERATOR_VERSION=${OPERATOR_VERSION}"
26+
echo "🔍 Fetching image list from ${IMAGE_SOURCE}..."
27+
28+
#########################################
29+
# Step 1: Fetch image list from operator
30+
#########################################
31+
operator_images=$(
32+
docker run --rm "${IMAGE_SOURCE}" --print-images=list 2>/dev/null \
33+
| grep -E '^[a-z0-9.-]+\.[a-z0-9.-]+/[a-z0-9._/-]+:[a-zA-Z0-9._-]+' \
34+
| grep -v -- '-fips' \
35+
| sort -u
36+
)
37+
38+
#########################################
39+
# Step 2: Extract from manifests
40+
#########################################
41+
manifest_dir="${SCRIPT_DIR}/../manifests"
42+
manifest_images=$(
43+
grep -rhoE 'image:\s*["'\''"]?[a-z0-9.-]+\.[a-z0-9.-]+/[a-z0-9._/-]+:[a-zA-Z0-9._-]+' "$manifest_dir" \
44+
| sed -E 's/image:\s*["'\''"]?//' \
45+
| grep -v -- '-fips' \
46+
| sort -u
47+
)
48+
49+
#########################################
50+
# Step 3: Combine and deduplicate
51+
#########################################
52+
all_images=$(echo -e "${operator_images}\n${manifest_images}" | sort -u)
53+
count=$(echo "$all_images" | wc -l)
54+
55+
echo "📦 Total unique images to check (excluding -fips): ${count}"
56+
57+
#########################################
58+
# Step 4: Check availability with retries
59+
#########################################
60+
FAILED=0
61+
FAILED_IMAGES=()
62+
63+
while IFS= read -r image; do
64+
success=0
65+
for attempt in 1 2 3; do
66+
if "$CRANE" digest "$image" >/dev/null 2>&1; then
67+
echo "✅ Available: $image"
68+
success=1
69+
break
70+
else
71+
echo "⚠️ Attempt $attempt failed for: $image"
72+
if [ "$attempt" -eq 3 ]; then
73+
echo "🔍 Used crane at: $(realpath "$CRANE" 2>/dev/null || echo '<unresolvable>')"
74+
fi
75+
sleep 3
76+
fi
77+
done
78+
79+
if [ "$success" -ne 1 ]; then
80+
echo "❌ NOT FOUND after 3 attempts: $image"
81+
FAILED=1
82+
FAILED_IMAGES+=("$image")
83+
fi
84+
done <<< "$all_images"
85+
86+
#########################################
87+
# Step 5: Final result
88+
#########################################
89+
if [ "$FAILED" -eq 1 ]; then
90+
echo ""
91+
echo "❗ Some images are missing or invalid:"
92+
for img in "${FAILED_IMAGES[@]}"; do
93+
echo "$img"
94+
done
95+
exit 1
96+
else
97+
echo "🎉 All images are available!"
98+
fi

lib.Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,26 @@ bin/yq:
12491249
tar -zxvf $(TMP)/yq4.tar.gz -C $(TMP)
12501250
mv $(TMP)/yq_linux_$(BUILDARCH) bin/yq
12511251

1252+
# This setup is used to download and install the 'crane' binary into the local bin/ directory.
1253+
# The binary will be placed at: ./bin/crane
1254+
# Normalize architecture for go-containerregistry filenames
1255+
CRANE_BUILDARCH := $(shell uname -m | sed 's/amd64/x86_64/;s/x86_64/x86_64/;s/aarch64/arm64/')
1256+
ifeq ($(CRANE_BUILDARCH),)
1257+
$(error Unsupported or unknown architecture: $(shell uname -m))
1258+
endif
1259+
CRANE_VERSION := v0.20.6
1260+
CRANE_FILENAME := go-containerregistry_Linux_$(CRANE_BUILDARCH).tar.gz
1261+
CRANE_URL := https://github.com/google/go-containerregistry/releases/download/$(CRANE_VERSION)/$(CRANE_FILENAME)
1262+
1263+
# Install crane binary into bin/
1264+
bin/crane:
1265+
mkdir -p bin
1266+
$(eval TMP := $(shell mktemp -d))
1267+
curl -sSfL --retry 5 -o $(TMP)/crane.tar.gz $(CRANE_URL)
1268+
tar -xzf $(TMP)/crane.tar.gz -C $(TMP) crane
1269+
mv $(TMP)/crane bin/crane
1270+
chmod +x bin/crane
1271+
12521272
###############################################################################
12531273
# Common functions for launching a local Kubernetes control plane.
12541274
###############################################################################

0 commit comments

Comments
 (0)