Skip to content

Commit d663b07

Browse files
committed
test images: Fixes echoserver s390x image
When trying to build the s390x image, it would fail when running the apk command with the following error: ERROR: Unable to open root: Bad address ERROR: Failed to open apk database: Bad address This can be fixed by updating the third_party/multiarch/qemu-user-static/register/register.sh and third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh scripts and their usage to a newer version [1]. Additionally, the packages nginx-mod-http-lua and nginx-mod-http-lua-upstream cannot be found in the regular http://dl-cdn.alpinelinux.org/alpine/v3.9/main/s390x/ repository, but we can use an older one [2]. [1] https://github.com/qemu/qemu/blob/master/scripts/qemu-binfmt-conf.sh [2] http://dl-cdn.alpinelinux.org/alpine/v3.8/main
1 parent e1fd2d7 commit d663b07

File tree

5 files changed

+101
-50
lines changed

5 files changed

+101
-50
lines changed

test/images/echoserver/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ FROM $BASEIMAGE
1717

1818
CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/
1919

20-
RUN apk add --no-cache openssl nginx-mod-http-lua nginx-mod-http-lua-upstream
20+
COPY install-deps.sh /
21+
RUN ["sh", "-c", "/install-deps.sh"]
2122
RUN mkdir -p /run/nginx
2223

2324
ADD nginx.conf /etc/nginx/nginx.conf
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# Copyright 2020 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
ARCH=$(uname -m)
18+
19+
if [ "${ARCH}" = "s390x" ]; then
20+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.8/main" > /etc/apk/repositories
21+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.8/community" >> /etc/apk/repositories
22+
fi
23+
24+
apk add --no-cache openssl nginx-mod-http-lua nginx-mod-http-lua-upstream
25+
26+
exit 0

test/images/image-util.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ build() {
140140
if [[ $(id -u) != 0 ]]; then
141141
sudo=sudo
142142
fi
143-
${sudo} "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset
143+
${sudo} "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset -p yes
144144
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/"${QEMUVERSION}"/x86_64_qemu-"${QEMUARCHS[$arch]}"-static.tar.gz | tar -xz -C "${temp_dir}"
145145
# Ensure we don't get surprised by umask settings
146146
chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"
@@ -256,8 +256,7 @@ if [[ "${WHAT}" == "all-conformance" ]]; then
256256
# no point in rebuilding all of them every time. This will only build the Conformance-related images.
257257
# Discussed during Conformance Office Hours Meeting (2019.12.17):
258258
# https://docs.google.com/document/d/1W31nXh9RYAb_VaYkwuPLd1hFxuRX3iU0DmaQ4lkCsX8/edit#heading=h.l87lu17xm9bh
259-
# echoserver image not included: https://github.com/kubernetes/kubernetes/issues/84158
260-
conformance_images=("busybox" "agnhost" "jessie-dnsutils" "kitten" "nautilus" "nonewprivs" "resource-consumer" "sample-apiserver")
259+
conformance_images=("busybox" "agnhost" "echoserver" "jessie-dnsutils" "kitten" "nautilus" "nonewprivs" "resource-consumer" "sample-apiserver")
261260
for image in "${conformance_images[@]}"; do
262261
eval "${TASK}" "${image}"
263262
done

third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@
44
#
55
# downloaded from https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh
66

7-
qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
8-
mips mipsel mipsn32 mipsn32el mips64 mips64el \
9-
sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb microblaze microblazeel"
7+
# Enable automatic program execution by the kernel.
8+
9+
qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \
10+
ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \
11+
sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \
12+
microblaze microblazeel or1k x86_64"
1013

1114
i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
12-
i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
15+
i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
1316
i386_family=i386
1417

1518
i486_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'
16-
i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
19+
i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
1720
i486_family=i386
1821

22+
x86_64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'
23+
x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
24+
x86_64_family=i386
25+
1926
alpha_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
20-
alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
27+
alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
2128
alpha_family=alpha
2229

2330
arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
@@ -29,13 +36,17 @@ armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff
2936
armeb_family=armeb
3037

3138
sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
32-
sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
39+
sparc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
3340
sparc_family=sparc
3441

3542
sparc32plus_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'
36-
sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
43+
sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
3744
sparc32plus_family=sparc
3845

46+
sparc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
47+
sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
48+
sparc64_family=sparc
49+
3950
ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
4051
ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
4152
ppc_family=ppc
@@ -49,7 +60,7 @@ ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\x
4960
ppc64le_family=ppcle
5061

5162
m68k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
52-
m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
63+
m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
5364
m68k_family=m68k
5465

5566
# FIXME: We could use the other endianness on a MIPS host.
@@ -79,11 +90,11 @@ mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\
7990
mips64el_family=mips
8091

8192
sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
82-
sh4_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
93+
sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
8394
sh4_family=sh4
8495

8596
sh4eb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
86-
sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
97+
sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
8798
sh4eb_family=sh4
8899

89100
s390x_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
@@ -126,6 +137,10 @@ microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\
126137
microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
127138
microblazeel_family=microblazeel
128139

140+
or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c'
141+
or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
142+
or1k_family=or1k
143+
129144
qemu_get_family() {
130145
cpu=${HOST_ARCH:-$(uname -m)}
131146
case "$cpu" in
@@ -163,21 +178,26 @@ usage() {
163178
cat <<EOF
164179
Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
165180
[--help][--credential yes|no][--exportdir PATH]
181+
[--persistent yes|no][--qemu-suffix SUFFIX]
166182
167183
Configure binfmt_misc to use qemu interpreter
168184
169-
--help: display this usage
170-
--qemu-path: set path to qemu interpreter ($QEMU_PATH)
171-
--debian: don't write into /proc,
172-
instead generate update-binfmts templates
173-
--systemd: don't write into /proc,
174-
instead generate file for systemd-binfmt.service
175-
for the given CPU. If CPU is "ALL", generate a
176-
file for all known cpus
177-
--exportdir: define where to write configuration files
178-
(default: $SYSTEMDDIR or $DEBIANDIR)
179-
--credential: if yes, credential and security tokens are
180-
calculated according to the binary to interpret
185+
--help: display this usage
186+
--qemu-path: set path to qemu interpreter ($QEMU_PATH)
187+
--qemu-suffix: add a suffix to the default interpreter name
188+
--debian: don't write into /proc,
189+
instead generate update-binfmts templates
190+
--systemd: don't write into /proc,
191+
instead generate file for systemd-binfmt.service
192+
for the given CPU. If CPU is "ALL", generate a
193+
file for all known cpus
194+
--exportdir: define where to write configuration files
195+
(default: $SYSTEMDDIR or $DEBIANDIR)
196+
--credential: if yes, credential and security tokens are
197+
calculated according to the binary to interpret
198+
--persistent: if yes, the interpreter is loaded when binfmt is
199+
configured and remains in memory. All future uses
200+
are cloned from the open file.
181201
182202
To import templates with update-binfmts, use :
183203
@@ -243,7 +263,15 @@ qemu_check_systemd() {
243263
}
244264

245265
qemu_generate_register() {
246-
echo ":qemu-$cpu:M::$magic:$mask:$qemu:$FLAGS"
266+
flags=""
267+
if [ "$CREDENTIAL" = "yes" ] ; then
268+
flags="OC"
269+
fi
270+
if [ "$PERSISTENT" = "yes" ] ; then
271+
flags="${flags}F"
272+
fi
273+
274+
echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags"
247275
}
248276

249277
qemu_register_interpreter() {
@@ -262,10 +290,8 @@ package qemu-$cpu
262290
interpreter $qemu
263291
magic $magic
264292
mask $mask
293+
credential $CREDENTIAL
265294
EOF
266-
if [ "$FLAGS" = "OC" ] ; then
267-
echo "credentials yes" >> "$EXPORTDIR/qemu-$cpu"
268-
fi
269295
}
270296

271297
qemu_set_binfmts() {
@@ -284,11 +310,12 @@ qemu_set_binfmts() {
284310
continue
285311
fi
286312

287-
qemu="$QEMU_PATH/qemu-$cpu-static"
313+
qemu="$QEMU_PATH/qemu-$cpu"
288314
if [ "$cpu" = "i486" ] ; then
289-
qemu="$QEMU_PATH/qemu-i386-static"
315+
qemu="$QEMU_PATH/qemu-i386"
290316
fi
291317

318+
qemu="$qemu$QEMU_SUFFIX"
292319
if [ "$host_family" != "$family" ] ; then
293320
$BINFMT_SET
294321
fi
@@ -302,9 +329,11 @@ SYSTEMDDIR="/etc/binfmt.d"
302329
DEBIANDIR="/usr/share/binfmts"
303330

304331
QEMU_PATH=/usr/local/bin
305-
FLAGS=""
332+
CREDENTIAL=no
333+
PERSISTENT=no
334+
QEMU_SUFFIX=""
306335

307-
options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@")
336+
options=$(getopt -o ds:Q:S:e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: -- "$@")
308337
eval set -- "$options"
309338

310339
while true ; do
@@ -340,6 +369,10 @@ while true ; do
340369
shift
341370
QEMU_PATH="$1"
342371
;;
372+
-F|--qemu-suffix)
373+
shift
374+
QEMU_SUFFIX="$1"
375+
;;
343376
-e|--exportdir)
344377
shift
345378
EXPORTDIR="$1"
@@ -350,11 +383,11 @@ while true ; do
350383
;;
351384
-c|--credential)
352385
shift
353-
if [ "$1" = "yes" ] ; then
354-
FLAGS="OC"
355-
else
356-
FLAGS=""
357-
fi
386+
CREDENTIAL="$1"
387+
;;
388+
-p|--persistent)
389+
shift
390+
PERSISTENT="$1"
358391
;;
359392
*)
360393
break

third_party/multiarch/qemu-user-static/register/register.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
1414
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
1515
fi
1616

17-
entries="aarch64 aarch64_be alpha arm armeb hppa m68k microblaze microblazeel mips mips64 mips64el mipsel mipsn32 mipsn32el ppc ppc64 ppc64le riscv32 riscv64 s390x sh4 sh4eb sparc sparc32plus sparc64 xtensa xtensaeb"
1817

1918
if [ "${1}" = "--reset" ]; then
2019
shift
21-
(
22-
cd /proc/sys/fs/binfmt_misc || exit
23-
for file in $entries; do
24-
if [ -f "qemu-${file}" ]; then
25-
echo -1 > "qemu-${file}"
26-
fi
27-
done
28-
)
20+
find /proc/sys/fs/binfmt_misc -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \;
2921
fi
3022

31-
exec $(dirname "${BASH_SOURCE[0]}")/qemu-binfmt-conf.sh --qemu-path="${QEMU_BIN_DIR}" "$@"
23+
exec $(dirname "${BASH_SOURCE[0]}")/qemu-binfmt-conf.sh --qemu-suffix "-static" --qemu-path="${QEMU_BIN_DIR}" "$@"

0 commit comments

Comments
 (0)