Skip to content

Commit 8bbe3a4

Browse files
script to retrieve airgap images from running cluster (#120)
* script to retrieve airgap images from running cluster * add airgap scripts based on PR #120 --------- Co-authored-by: Alberto Morgante Medina <alberto.morgante@suse.com>
1 parent 9a63e77 commit 8bbe3a4

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

airgap-images/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Airgap images
2+
3+
There are two types of airgap images:
4+
5+
- Rancher images
6+
7+
- EIB images for the mgmt-cluster
8+
9+
## Requirements
10+
11+
To retrieve the airgap images, you need to have the following tools installed:
12+
13+
- helm `curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash`
14+
15+
**IMPORTANT**: You need to run the following scripts in a cluster deployed with the final versions (the release you want to retrieve the airgap images list)
16+
17+
18+
## Airgap images for the management cluster
19+
20+
The airgap images for the management cluster are located in the `airgap-images` directory. The images are used to create a management cluster that is not connected to the internet. The images are stored in a tar file and can be loaded into the local container registry using the following command:
21+
22+
```bash
23+
./eib-mgmt-cluster-airgap-images.sh
24+
```
25+
26+
This command will show you the full list images to be included in the EIB definition file for airgap scenarios
27+
28+
29+
## Airgap images for rancher guide
30+
31+
```
32+
./retrieve-rancher-airgap-images.sh
33+
```
34+
35+
This will show you the list of images to be included in the rancher guide for airgap environments
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
kubectl get pods --all-namespaces -o jsonpath="{..image}" | tr -s '[[:space:]]' '\n' | sort | uniq
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# CONFIGURATION ———
5+
WORKDIR="./hauler_temp"
6+
mkdir -p "${WORKDIR}"
7+
8+
# Add & update the Prime Helm repo
9+
helm repo add rancher-prime https://charts.rancher.com/server-charts/prime
10+
helm repo update
11+
12+
# Auto-detect Rancher version from your cluster (fallback to Helm)
13+
if RANCHER_IMAGE=$(kubectl -n cattle-system get deployment rancher \
14+
-o jsonpath='{.spec.template.spec.containers[0].image}' 2>/dev/null); then
15+
RANCHER_VERSION="${RANCHER_IMAGE##*:}"
16+
echo "Detected Rancher image in cluster: ${RANCHER_IMAGE}"
17+
echo "Using Rancher version: ${RANCHER_VERSION}"
18+
else
19+
echo "Could not detect Rancher in cattle-system, falling back to Helm query"
20+
RANCHER_VERSION=$(helm search repo rancher-prime/rancher \
21+
| awk 'NR==2 {print $3}')
22+
echo "Using Rancher GitHub release tag: ${RANCHER_VERSION}"
23+
fi
24+
25+
# Download & fail if the tag doesn’t exist
26+
PRIME_BASE="https://prime.ribs.rancher.io/rancher/${RANCHER_VERSION}"
27+
curl -fSL "${PRIME_BASE}/rancher-images.txt" \
28+
-o "${WORKDIR}/orig-rancher-images.txt" \
29+
|| {
30+
echo >&2 "ERROR: Rancher Prime release ${RANCHER_VERSION} not found at ${PRIME_BASE}"
31+
exit 1
32+
}
33+
34+
# Filter out unneeded images
35+
sed -E '/neuvector|minio|gke|aks|eks|sriov|harvester|mirrored|longhorn|thanos|tekton|istio|hyper|jenkins|windows/d' \
36+
"${WORKDIR}/orig-rancher-images.txt" \
37+
> "${WORKDIR}/cleaned-rancher-images.txt"
38+
39+
# Re-add Cluster API and kubectl entries
40+
grep cluster-api "${WORKDIR}/orig-rancher-images.txt" >> "${WORKDIR}/cleaned-rancher-images.txt"
41+
grep kubectl "${WORKDIR}/orig-rancher-images.txt" >> "${WORKDIR}/cleaned-rancher-images.txt"
42+
43+
# ——— 5. Pick the latest tag for each repo ———
44+
> "${WORKDIR}/rancher-unsorted.txt"
45+
awk -F: '{print $1}' "${WORKDIR}/cleaned-rancher-images.txt" | sort -u |
46+
while read -r repo; do
47+
grep -w "$repo" "${WORKDIR}/cleaned-rancher-images.txt" \
48+
| sort -Vr | head -1 \
49+
>> "${WORKDIR}/rancher-unsorted.txt"
50+
done
51+
52+
# Final sort & dedupe
53+
sort -u "${WORKDIR}/rancher-unsorted.txt" > "${WORKDIR}/rancher-images.txt"
54+
55+
# Manual fix-ups
56+
{
57+
echo "rancher/kubectl:v1.20.2"
58+
echo "rancher/shell:v0.1.24"
59+
grep mirrored-ingress-nginx "${WORKDIR}/orig-rancher-images.txt"
60+
} >> "${WORKDIR}/rancher-images.txt"
61+
62+
# Generate airgap_hauler.yaml
63+
cat > airgap_hauler.yaml <<EOF
64+
images:
65+
EOF
66+
while read -r img; do
67+
echo " - name: ${img}"
68+
done < "${WORKDIR}/rancher-images.txt" >> airgap_hauler.yaml
69+
70+
echo "${WORKDIR}/rancher-images.txt"
71+
echo " • airgap_hauler.yaml"

0 commit comments

Comments
 (0)