22
33set -e
44
5- header () {
5+ function header() {
66 local text=" $1 "
77 local width=53 # Adjust this for desired total width
88 local padding=$(( (width - ${# text} ) / 2 )) # Calculate padding for centering
@@ -12,9 +12,42 @@ header() {
1212 printf ' %*s\n' " $width " | tr ' ' ' -'
1313}
1414
15- verifyKuberlrKubectl () {
15+ function error() {
16+ local text=" $1 "
17+ local width=53 # Adjust this for desired total width
18+ local padding=$(( (width - ${# text} ) / 2 )) # Calculate padding for centering
19+
20+ # ANSI escape codes for styling
21+ local RED_BOLD=' \033[1;31m' # Bold Red text
22+ local RESET=' \033[0m' # Reset text formatting
23+
24+ # Print the error message in red and bold
25+ echo -e " ${RED_BOLD} "
26+ printf ' %*s\n' " $width " | tr ' ' ' -'
27+ printf ' %*s%s%*s\n' " $padding " " " " $text " " $padding " " "
28+ printf ' %*s\n' " $width " | tr ' ' ' -'
29+ echo -e " ${RESET} "
30+ }
31+
32+ function expectedArch() {
33+ IMAGE_ARCH=$1
34+ case $IMAGE_ARCH in
35+ amd64)
36+ echo " x86-64"
37+ ;;
38+ arm64)
39+ echo " aarch64"
40+ ;;
41+ * )
42+ echo " UNKNOWN-ARCH"
43+ ;;
44+ esac
45+ }
46+
47+ function verifyKuberlrKubectl() {
1648 # Loop through each architecture
1749 for ARCH in $ARCHES ; do
50+ EXPECTED_BIN_ARCH=$( expectedArch " $ARCH " )
1851 ARCH_DIR=" $WORKDIR /$ARCH "
1952 mkdir -p " $ARCH_DIR "
2053
@@ -32,12 +65,30 @@ verifyKuberlrKubectl() {
3265 header " $ARCH - kuberlr BINs"
3366 # Verify architecture
3467 if [[ -f " $ARCH_DIR /kuberlr" ]]; then
35- echo -n " kuberlr: " && file " $ARCH_DIR /kuberlr"
68+ FILE_INFO=$( file " $ARCH_DIR /kuberlr" )
69+ echo -n " kuberlr info:" ;
70+ echo " $FILE_INFO "
71+ if [[ " $FILE_INFO " == * " $EXPECTED_BIN_ARCH " * ]]; then
72+ echo " Bin is expected arch"
73+ else
74+ error " ERROR - Bin NOT expected arch"
75+ echo " Expected: $EXPECTED_BIN_ARCH "
76+ exit 1
77+ fi
3678 fi
3779 header " $ARCH - Kubectl BINs"
3880 for KUBECTL_VER in $KUBECTL_LIST ; do
3981 if [[ -f " $ARCH_DIR /$KUBECTL_VER " ]]; then
40- echo -n " kuberlr($KUBECTL_VER ): " && file " $ARCH_DIR /$KUBECTL_VER "
82+ FILE_INFO=$( file " $ARCH_DIR /$KUBECTL_VER " )
83+ echo -n " kuberlr($KUBECTL_VER ) info:" ;
84+ echo " $FILE_INFO "
85+ if [[ " $FILE_INFO " == * " $EXPECTED_BIN_ARCH " * ]]; then
86+ echo " Bin is expected arch"
87+ else
88+ error " ERROR - Bin NOT expected arch"
89+ echo " Expected: $EXPECTED_BIN_ARCH "
90+ exit 1
91+ fi
4192 fi
4293 done
4394
56107# Check if the user provided an image name and tag
57108if [ " $# " -ne 1 ]; then
58109 echo " Usage: $0 <image_name:tag>"
110+ echo " This script is used to help verify the contents of ` rancher/kuberlr-kubectl` and ` flavior/kuberlr` images."
111+ echo " This script will verify:"
112+ echo " 1. The architectures of a mult-arch image,"
113+ echo " 2. The architecture of the image's required binaries (` kuberlr` and ` kubectl` )."
59114 exit 1
60115fi
61116
@@ -74,10 +129,12 @@ if [ -z "$ARCHES" ]; then
74129 exit 1
75130fi
76131
77- echo " Architectures found: $ARCHES "
132+ SINGLE_LINE_ARCH=$( echo " ${ARCHES} " | tr ' \n' ' ,' | sed ' s/,$//' )
133+ echo " Architectures found: $SINGLE_LINE_ARCH "
78134if [[ " $IMAGE " == * /kuberlr:* ]]; then
79135 # Loop through each architecture
80136 for ARCH in $ARCHES ; do
137+ EXPECTED_BIN_ARCH=$( expectedArch " $ARCH " )
81138 ARCH_DIR=" $WORKDIR /$ARCH "
82139 mkdir -p " $ARCH_DIR "
83140
@@ -91,7 +148,16 @@ if [[ "$IMAGE" == */kuberlr:* ]]; then
91148 header " $ARCH - kuberlr BINs"
92149 # Verify architecture
93150 if [[ -f " $ARCH_DIR /kuberlr" ]]; then
94- echo -n " kuberlr: " && file " $ARCH_DIR /kuberlr"
151+ FILE_INFO=$( file " $ARCH_DIR /kuberlr" )
152+ echo -n " kuberlr info:" ;
153+ echo " $FILE_INFO "
154+ if [[ " $FILE_INFO " == * " $EXPECTED_BIN_ARCH " * ]]; then
155+ echo " Bin is expected arch"
156+ else
157+ error " ERROR - Bin NOT expected arch"
158+ echo " Expected: $EXPECTED_BIN_ARCH for $ARCH "
159+ exit 1
160+ fi
95161 fi
96162
97163 echo " Done processing $ARCH ."
0 commit comments