Skip to content

Commit 1e940d4

Browse files
authored
Merge pull request #46 from rancher/gha-portpr-13373839641-1
[backport release/v3.x] fix(kuberlr): cpu archetecture bug fix
2 parents d9d7b21 + 5ad861a commit 1e940d4

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG BCI_VERSION=15.6
2-
FROM ghcr.io/flavio/kuberlr:v0.5.2 AS kuberlr
2+
FROM ghcr.io/flavio/kuberlr:v0.5.3 AS kuberlr
33
FROM registry.suse.com/bci/bci-busybox:${BCI_VERSION} AS final
44
FROM registry.suse.com/bci/bci-base:${BCI_VERSION} AS zypper
55

scripts/check-image-binaries

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
header() {
6+
local text="$1"
7+
local width=53 # Adjust this for desired total width
8+
local padding=$(( (width - ${#text}) / 2 )) # Calculate padding for centering
9+
10+
printf '%*s\n' "$width" | tr ' ' '-'
11+
printf '%*s%s%*s\n' "$padding" "" "$text" "$padding" ""
12+
printf '%*s\n' "$width" | tr ' ' '-'
13+
}
14+
15+
verifyKuberlrKubectl() {
16+
# Loop through each architecture
17+
for ARCH in $ARCHES; do
18+
ARCH_DIR="$WORKDIR/$ARCH"
19+
mkdir -p "$ARCH_DIR"
20+
21+
header "Processing architecture: $ARCH"
22+
23+
# Pull and extract files
24+
CONTAINER_ID=$(docker create --platform linux/$ARCH "$IMAGE")
25+
docker cp "$CONTAINER_ID:/bin/kuberlr" "$ARCH_DIR/kuberlr" 2>&1 > /dev/null || echo "kuberlr not found in $IMAGE for $ARCH"
26+
KUBECTL_LIST=$(docker run --rm --entrypoint sh rancher/kuberlr-kubectl:v4.0.1 -c "ls /usr/bin | grep kube")
27+
for KUBECTL_VER in $KUBECTL_LIST; do
28+
docker cp "$CONTAINER_ID:/usr/bin/$KUBECTL_VER" "$ARCH_DIR/$KUBECTL_VER" 2>&1 > /dev/null || echo "kubectl ($KUBECTL_VER) not found in $IMAGE for $ARCH"
29+
done
30+
docker rm "$CONTAINER_ID" 2>&1 > /dev/null
31+
32+
header "$ARCH - kuberlr BINs"
33+
# Verify architecture
34+
if [[ -f "$ARCH_DIR/kuberlr" ]]; then
35+
echo -n "kuberlr: " && file "$ARCH_DIR/kuberlr"
36+
fi
37+
header "$ARCH - Kubectl BINs"
38+
for KUBECTL_VER in $KUBECTL_LIST; do
39+
if [[ -f "$ARCH_DIR/$KUBECTL_VER" ]]; then
40+
echo -n "kuberlr($KUBECTL_VER): " && file "$ARCH_DIR/$KUBECTL_VER"
41+
fi
42+
done
43+
44+
echo "Done processing $ARCH."
45+
done
46+
}
47+
48+
# Ensure required commands are available
49+
for cmd in docker jq file; do
50+
if ! command -v $cmd &>/dev/null; then
51+
echo "Error: $cmd is not installed." >&2
52+
exit 1
53+
fi
54+
done
55+
56+
# Check if the user provided an image name and tag
57+
if [ "$#" -ne 1 ]; then
58+
echo "Usage: $0 <image_name:tag>"
59+
exit 1
60+
fi
61+
62+
IMAGE="$1"
63+
64+
# Create a working directory
65+
WORKDIR="./image_arch_test"
66+
mkdir -p "$WORKDIR"
67+
68+
# Fetch architectures using docker buildx imagetools
69+
echo "Fetching architectures for $IMAGE..."
70+
ARCHES=$(docker buildx imagetools inspect "$IMAGE" --format '{{json .Manifest.Manifests}}' | jq -r '.[].platform.architecture'|sort|uniq|grep -v unknown)
71+
72+
if [ -z "$ARCHES" ]; then
73+
echo "Failed to fetch architectures. Is the image multi-arch?"
74+
exit 1
75+
fi
76+
77+
echo "Architectures found: $ARCHES"
78+
if [[ "$IMAGE" == */kuberlr:* ]]; then
79+
# Loop through each architecture
80+
for ARCH in $ARCHES; do
81+
ARCH_DIR="$WORKDIR/$ARCH"
82+
mkdir -p "$ARCH_DIR"
83+
84+
header "Processing architecture: $ARCH"
85+
86+
# Pull and extract files
87+
CONTAINER_ID=$(docker create --platform linux/$ARCH "$IMAGE")
88+
docker cp "$CONTAINER_ID:/bin/kuberlr" "$ARCH_DIR/kuberlr" 2>&1 > /dev/null || echo "kuberlr not found in $IMAGE for $ARCH"
89+
docker rm "$CONTAINER_ID" 2>&1 > /dev/null
90+
91+
header "$ARCH - kuberlr BINs"
92+
# Verify architecture
93+
if [[ -f "$ARCH_DIR/kuberlr" ]]; then
94+
echo -n "kuberlr: " && file "$ARCH_DIR/kuberlr"
95+
fi
96+
97+
echo "Done processing $ARCH."
98+
done
99+
else
100+
verifyKuberlrKubectl;
101+
fi
102+
103+
104+
echo "All architectures processed. Check $WORKDIR for results."

0 commit comments

Comments
 (0)