Skip to content

Commit 31530bf

Browse files
committed
debian-iptables: Build bullseye-v1.0.0 images
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 36a12d0 commit 31530bf

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

dependencies.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ dependencies:
445445
# match: "DEBIAN_BASE_VERSION: '(bullseye|buster)-v((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)'"
446446

447447
- name: "k8s.gcr.io/build-image/debian-iptables (next candidate)"
448-
version: buster-v1.6.7
448+
version: bullseye-v1.0.0
449449
refPaths:
450450
- path: images/build/debian-iptables/variants.yaml
451451
match: "IMAGE_VERSION: '(bullseye|buster)-v((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BASEIMAGE
16+
17+
FROM ${BASEIMAGE} as build
18+
19+
# Install iptables and ebtables packages from bullseye-backports
20+
RUN echo deb http://deb.debian.org/debian bullseye-backports main >> /etc/apt/sources.list \
21+
&& apt-get update \
22+
&& apt-get -t bullseye-backports -y --no-install-recommends install \
23+
iptables \
24+
ebtables
25+
26+
# Install other dependencies and then clean up apt caches
27+
RUN clean-install \
28+
conntrack \
29+
ipset \
30+
kmod \
31+
netbase
32+
33+
# Install iptables wrapper scripts to detect the correct iptables mode
34+
# the first time any of them is run
35+
COPY iptables-wrapper /usr/sbin/iptables-wrapper
36+
37+
RUN update-alternatives \
38+
--install /usr/sbin/iptables iptables /usr/sbin/iptables-wrapper 100 \
39+
--slave /usr/sbin/iptables-restore iptables-restore /usr/sbin/iptables-wrapper \
40+
--slave /usr/sbin/iptables-save iptables-save /usr/sbin/iptables-wrapper
41+
RUN update-alternatives \
42+
--install /usr/sbin/ip6tables ip6tables /usr/sbin/iptables-wrapper 100 \
43+
--slave /usr/sbin/ip6tables-restore ip6tables-restore /usr/sbin/iptables-wrapper \
44+
--slave /usr/sbin/ip6tables-save ip6tables-save /usr/sbin/iptables-wrapper
45+
46+
FROM scratch
47+
COPY --from=build / /
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
# Copyright 2021 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+
set -e
18+
19+
# Detect whether the base system is using iptables-legacy or
20+
# iptables-nft. This assumes that some non-containerized process (eg
21+
# kubelet) has already created some iptables rules.
22+
23+
# Bugs in iptables-nft 1.8.3 may cause it to get stuck in a loop in
24+
# some circumstances, so we have to run the nft check in a timeout. To
25+
# avoid hitting that timeout, we only bother to even check nft if
26+
# legacy iptables was empty / mostly empty.
27+
28+
num_legacy_lines=$( (iptables-legacy-save || true; ip6tables-legacy-save || true) 2>/dev/null | grep '^-' | wc -l || true)
29+
num_nft_lines=$( (timeout 5 sh -c "iptables-nft-save; ip6tables-nft-save" || true) 2>/dev/null | grep '^-' | wc -l || true)
30+
if [ "${num_legacy_lines}" -ge "${num_nft_lines}" ]; then
31+
mode=legacy
32+
else
33+
mode=nft
34+
fi
35+
36+
update-alternatives --set iptables "/usr/sbin/iptables-${mode}" > /dev/null
37+
update-alternatives --set ip6tables "/usr/sbin/ip6tables-${mode}" > /dev/null
38+
39+
# Now re-exec the original command with the newly-selected alternative
40+
exec "$0" "$@"

0 commit comments

Comments
 (0)