Skip to content

Commit bf9581f

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

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed

.semaphore/semaphore.yml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.semaphore/semaphore.yml.d/02-global_job_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
global_job_config:
22
secrets:
33
- name: docker-hub
4+
- name: oss-release-secrets
45
prologue:
56
commands:
67
- checkout
@@ -10,6 +11,8 @@ global_job_config:
1011
# unshallow it for GIT_VERSION:=$(shell git describe --tags --dirty --always)
1112
- retry git fetch --unshallow
1213
- echo $DOCKERHUB_PASSWORD | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
14+
- export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/gcr-credentials.json
15+
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
1316
epilogue:
1417
commands:
1518
- cd "$REPO_DIR"

.semaphore/semaphore.yml.d/blocks/10-prerequisites.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
- name: Pre-flight checks
66
commands:
77
- make ci-preflight-checks
8+
secrets:
9+
- name: oss-release-secrets
10+
prologue:
11+
commands:
12+
- export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/gcr-credentials.json
13+
- echo "🔐 Authenticating to GCR using GOOGLE_APPLICATION_CREDENTIALS"
14+
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

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