Skip to content

Commit 33aac3d

Browse files
authored
Merge pull request #14579 from spowelljr/updateEntrypoint
Update entrypoint and kindnetd
2 parents fbb15ab + 8cdcc8d commit 33aac3d

File tree

4 files changed

+114
-60
lines changed

4 files changed

+114
-60
lines changed

deploy/kicbase/entrypoint

Lines changed: 110 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ grep_allow_nomatch() {
3333
grep "$@" || [[ $? == 1 ]]
3434
}
3535

36+
# regex_escape_ip converts IP address string $1 to a regex-escaped literal
37+
regex_escape_ip(){
38+
sed -e 's#\.#\\.#g' -e 's#\[#\\[#g' -e 's#\]#\\]#g' <<<"$1"
39+
}
40+
3641
validate_userns() {
3742
if [[ -z "${userns}" ]]; then
3843
return
@@ -56,43 +61,43 @@ validate_userns() {
5661
}
5762

5863
overlayfs_preferrable() {
59-
if [[ -z "$userns" ]]; then
60-
# If we are outside userns, we can always assume overlayfs is preferrable
61-
return 0
62-
fi
63-
64-
# Debian 10 and 11 supports overlayfs in userns with a "permit_mount_in_userns" kernel patch,
65-
# but known to be unstable, so we avoid using it https://github.com/moby/moby/issues/42302
66-
if [[ -e "/sys/module/overlay/parameters/permit_mounts_in_userns" ]]; then
67-
echo "INFO: UserNS: kernel seems supporting overlayfs with permit_mounts_in_userns, but avoiding due to instability."
68-
return 1
69-
fi
70-
71-
# Check overlayfs availability, by attempting to mount it.
72-
#
73-
# Overlayfs inside userns is known to be available for the following environments:
74-
# - Kernel >= 5.11 (but 5.11 and 5.12 have issues on SELinux hosts. Fixed in 5.13.)
75-
# - Ubuntu kernel
76-
# - Debian kernel (but avoided due to instability, see the /sys/module/overlay/... check above)
77-
# - Sysbox
78-
tmp=$(mktemp -d)
79-
mkdir -p "${tmp}/l" "${tmp}/u" "${tmp}/w" "${tmp}/m"
80-
if ! mount -t overlay -o lowerdir="${tmp}/l,upperdir=${tmp}/u,workdir=${tmp}/w" overlay "${tmp}/m"; then
81-
echo "INFO: UserNS: kernel does not seem to support overlayfs."
82-
rm -rf "${tmp}"
83-
return 1
84-
fi
85-
umount "${tmp}/m"
86-
rm -rf "${tmp}"
87-
88-
# Detect whether SELinux is Enforcing (or Permitted) by grepping /proc/self/attr/current .
89-
# Note that we cannot use `getenforce` command here because /sys/fs/selinux is typically not mounted for containers.
90-
if grep -q "_t:" "/proc/self/attr/current"; then
91-
# When the kernel is before v5.13 and SELinux is enforced, fuse-overlayfs might be safer, so we print a warning (but not an error).
92-
# https://github.com/torvalds/linux/commit/7fa2e79a6bb924fa4b2de5766dab31f0f47b5ab6
93-
echo "WARN: UserNS: SELinux might be Enforcing. If you see an error related to overlayfs, try setting \`KIND_EXPERIMENTAL_CONTAINERD_SNAPSHOTTER=fuse-overlayfs\` ." >&2
94-
fi
95-
return 0
64+
if [[ -z "$userns" ]]; then
65+
# If we are outside userns, we can always assume overlayfs is preferrable
66+
return 0
67+
fi
68+
69+
# Debian 10 and 11 supports overlayfs in userns with a "permit_mount_in_userns" kernel patch,
70+
# but known to be unstable, so we avoid using it https://github.com/moby/moby/issues/42302
71+
if [[ -e "/sys/module/overlay/parameters/permit_mounts_in_userns" ]]; then
72+
echo "INFO: UserNS: kernel seems supporting overlayfs with permit_mounts_in_userns, but avoiding due to instability."
73+
return 1
74+
fi
75+
76+
# Check overlayfs availability, by attempting to mount it.
77+
#
78+
# Overlayfs inside userns is known to be available for the following environments:
79+
# - Kernel >= 5.11 (but 5.11 and 5.12 have issues on SELinux hosts. Fixed in 5.13.)
80+
# - Ubuntu kernel
81+
# - Debian kernel (but avoided due to instability, see the /sys/module/overlay/... check above)
82+
# - Sysbox
83+
tmp=$(mktemp -d)
84+
mkdir -p "${tmp}/l" "${tmp}/u" "${tmp}/w" "${tmp}/m"
85+
if ! mount -t overlay -o lowerdir="${tmp}/l,upperdir=${tmp}/u,workdir=${tmp}/w" overlay "${tmp}/m"; then
86+
echo "INFO: UserNS: kernel does not seem to support overlayfs."
87+
rm -rf "${tmp}"
88+
return 1
89+
fi
90+
umount "${tmp}/m"
91+
rm -rf "${tmp}"
92+
93+
# Detect whether SELinux is Enforcing (or Permitted) by grepping /proc/self/attr/current .
94+
# Note that we cannot use `getenforce` command here because /sys/fs/selinux is typically not mounted for containers.
95+
if grep -q "_t:" "/proc/self/attr/current"; then
96+
# When the kernel is before v5.13 and SELinux is enforced, fuse-overlayfs might be safer, so we print a warning (but not an error).
97+
# https://github.com/torvalds/linux/commit/7fa2e79a6bb924fa4b2de5766dab31f0f47b5ab6
98+
echo "WARN: UserNS: SELinux might be Enforcing. If you see an error related to overlayfs, try setting \`KIND_EXPERIMENTAL_CONTAINERD_SNAPSHOTTER=fuse-overlayfs\` ." >&2
99+
fi
100+
return 0
96101
}
97102

98103
configure_containerd() {
@@ -156,7 +161,7 @@ update-alternatives() {
156161
}
157162

158163
fix_mount() {
159-
echo 'INFO: ensuring we can execute mount/umount even with userns-remap'
164+
echo 'INFO: ensuring we can execute mount/umount even with userns-remap'
160165
# necessary only when userns-remap is enabled on the host, but harmless
161166
# The binary /bin/mount should be owned by root and have the setuid bit
162167
chown root:root "$(which mount)" "$(which umount)"
@@ -231,6 +236,8 @@ fix_cgroup() {
231236
return
232237
fi
233238
echo 'INFO: detected cgroup v1'
239+
# We're looking for the cgroup-path for the cpu controller for the
240+
# current process. this tells us what cgroup-path the container is in.
234241
local current_cgroup
235242
current_cgroup=$(grep -E '^[^:]*:([^:]*,)?cpu(,[^,:]*)?:.*' /proc/self/cgroup | cut -d: -f3)
236243
if [ "$current_cgroup" = "/" ]; then
@@ -248,16 +255,14 @@ fix_cgroup() {
248255
# See: https://d2iq.com/blog/running-kind-inside-a-kubernetes-cluster-for-continuous-integration
249256
# Capture initial state before modifying
250257
#
251-
# Basically we're looking for the cgroup-path for the cpu controller for the
252-
# current process. this tells us what cgroup-path the container is in.
253-
# Then we collect the subsystems that are active on this path.
258+
# Then we collect the subsystems that are active on our current process.
254259
# We assume the cpu controller is in use on all node containers,
255260
# and other controllers use the same sub-path.
256261
#
257262
# See: https://man7.org/linux/man-pages/man7/cgroups.7.html
258263
echo 'INFO: fix cgroup mounts for all subsystems'
259264
local cgroup_subsystems
260-
cgroup_subsystems=$(findmnt -lun -o source,target -t cgroup | grep "${current_cgroup}" | awk '{print $2}')
265+
cgroup_subsystems=$(findmnt -lun -o source,target -t cgroup | grep -F "${current_cgroup}" | awk '{print $2}')
261266
# Unmount the cgroup subsystems that are not known to runtime used to
262267
# run the container we are in. Those subsystems are not properly scoped
263268
# (i.e. the root cgroup is exposed, rather than something like docker/xxxx).
@@ -268,7 +273,7 @@ fix_cgroup() {
268273
#
269274
# See https://github.com/kubernetes/kubernetes/issues/109182
270275
local unsupported_cgroups
271-
unsupported_cgroups=$(findmnt -lun -o source,target -t cgroup | grep_allow_nomatch -v "${current_cgroup}" | awk '{print $2}')
276+
unsupported_cgroups=$(findmnt -lun -o source,target -t cgroup | grep_allow_nomatch -v -F "${current_cgroup}" | awk '{print $2}')
272277
if [ -n "$unsupported_cgroups" ]; then
273278
local mnt
274279
echo "$unsupported_cgroups" |
@@ -321,9 +326,15 @@ fix_cgroup() {
321326
mount --make-rprivate /sys/fs/cgroup
322327
echo "${cgroup_subsystems}" |
323328
while IFS= read -r subsystem; do
324-
mount_kubelet_cgroup_root "/kubelet" "${subsystem}"
325-
mount_kubelet_cgroup_root "/kubelet.slice" "${subsystem}"
329+
mount_kubelet_cgroup_root /kubelet "${subsystem}"
330+
mount_kubelet_cgroup_root /kubelet.slice "${subsystem}"
326331
done
332+
# workaround for hosts not running systemd
333+
# we only do this for kubelet.slice because it's not relevant when not using
334+
# the systemd cgroup driver
335+
if [[ ! "${cgroup_subsystems}" = */sys/fs/cgroup/systemd* ]]; then
336+
mount_kubelet_cgroup_root /kubelet.slice /sys/fs/cgroup/systemd
337+
fi
327338
}
328339

329340
retryable_fix_cgroup() {
@@ -406,13 +417,29 @@ select_iptables() {
406417
update-alternatives --set ip6tables "/usr/sbin/ip6tables-${mode}" > /dev/null
407418
}
408419

420+
fix_certificate() {
421+
local apiserver_crt_file="/etc/kubernetes/pki/apiserver.crt"
422+
local apiserver_key_file="/etc/kubernetes/pki/apiserver.key"
423+
424+
# Skip if this Node doesn't run kube-apiserver
425+
if [[ ! -f ${apiserver_crt_file} ]] || [[ ! -f ${apiserver_key_file} ]]; then
426+
return
427+
fi
428+
429+
# Deletes the certificate for kube-apiserver and generates a new one.
430+
# This is necessary because the old one doesn't match the current IP.
431+
echo 'INFO: clearing and regenerating the certificate for serving the Kubernetes API' >&2
432+
rm -f ${apiserver_crt_file} ${apiserver_key_file}
433+
kubeadm init phase certs apiserver --config /kind/kubeadm.conf
434+
}
435+
409436
enable_network_magic(){
410437
# well-known docker embedded DNS is at 127.0.0.11:53
411438
local docker_embedded_dns_ip='127.0.0.11'
412439

413440
# first we need to detect an IP to use for reaching the docker host
414441
local docker_host_ip
415-
docker_host_ip="$( (head -n1 <(getent ahostsv4 'host.docker.internal') | cut -d' ' -f1) || true)"
442+
docker_host_ip="$( (head -n1 <(timeout 5 getent ahostsv4 'host.docker.internal') | cut -d' ' -f1) || true)"
416443
# if the ip doesn't exist or is a loopback address use the default gateway
417444
if [[ -z "${docker_host_ip}" ]] || [[ $docker_host_ip =~ ^127\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
418445
docker_host_ip=$(ip -4 route show default | cut -d' ' -f3)
@@ -433,8 +460,19 @@ enable_network_magic(){
433460
cp /etc/resolv.conf /etc/resolv.conf.original
434461
sed -e "s/${docker_embedded_dns_ip}/${docker_host_ip}/g" /etc/resolv.conf.original >/etc/resolv.conf
435462

463+
local files_to_update=(
464+
/etc/kubernetes/manifests/etcd.yaml
465+
/etc/kubernetes/manifests/kube-apiserver.yaml
466+
/etc/kubernetes/manifests/kube-controller-manager.yaml
467+
/etc/kubernetes/manifests/kube-scheduler.yaml
468+
/etc/kubernetes/controller-manager.conf
469+
/etc/kubernetes/scheduler.conf
470+
/kind/kubeadm.conf
471+
/var/lib/kubelet/kubeadm-flags.env
472+
)
473+
local should_fix_certificate=false
436474
# fixup IPs in manifests ...
437-
curr_ipv4="$( (head -n1 <(getent ahostsv4 "$(hostname)") | cut -d' ' -f1) || true)"
475+
curr_ipv4="$( (head -n1 <(timeout 5 getent ahostsv4 "$(hostname)") | cut -d' ' -f1) || true)"
438476
echo "INFO: Detected IPv4 address: ${curr_ipv4}" >&2
439477
if [ -f /kind/old-ipv4 ]; then
440478
old_ipv4=$(cat /kind/old-ipv4)
@@ -444,17 +482,23 @@ enable_network_magic(){
444482
echo "ERROR: Have an old IPv4 address but no current IPv4 address (!)" >&2
445483
exit 1
446484
fi
447-
# kubernetes manifests are only present on control-plane nodes
448-
sed -i "s#${old_ipv4}#${curr_ipv4}#" /etc/kubernetes/manifests/*.yaml || true
449-
# this is no longer required with autodiscovery
450-
sed -i "s#${old_ipv4}#${curr_ipv4}#" /var/lib/kubelet/kubeadm-flags.env || true
485+
if [[ "${old_ipv4}" != "${curr_ipv4}" ]]; then
486+
should_fix_certificate=true
487+
sed_ipv4_command="s#\b$(regex_escape_ip "${old_ipv4}")\b#${curr_ipv4}#g"
488+
for f in "${files_to_update[@]}"; do
489+
# kubernetes manifests are only present on control-plane nodes
490+
if [[ -f "$f" ]]; then
491+
sed -i "${sed_ipv4_command}" "$f"
492+
fi
493+
done
494+
fi
451495
fi
452496
if [[ -n $curr_ipv4 ]]; then
453497
echo -n "${curr_ipv4}" >/kind/old-ipv4
454498
fi
455499

456500
# do IPv6
457-
curr_ipv6="$( (head -n1 <(getent ahostsv6 "$(hostname)") | cut -d' ' -f1) || true)"
501+
curr_ipv6="$( (head -n1 <(timeout 5 getent ahostsv6 "$(hostname)") | cut -d' ' -f1) || true)"
458502
echo "INFO: Detected IPv6 address: ${curr_ipv6}" >&2
459503
if [ -f /kind/old-ipv6 ]; then
460504
old_ipv6=$(cat /kind/old-ipv6)
@@ -463,14 +507,24 @@ enable_network_magic(){
463507
if [[ -z $curr_ipv6 ]]; then
464508
echo "ERROR: Have an old IPv6 address but no current IPv6 address (!)" >&2
465509
fi
466-
# kubernetes manifests are only present on control-plane nodes
467-
sed -i "s#${old_ipv6}#${curr_ipv6}#" /etc/kubernetes/manifests/*.yaml || true
468-
# this is no longer required with autodiscovery
469-
sed -i "s#${old_ipv6}#${curr_ipv6}#" /var/lib/kubelet/kubeadm-flags.env || true
510+
if [[ "${old_ipv6}" != "${curr_ipv6}" ]]; then
511+
should_fix_certificate=true
512+
sed_ipv6_command="s#\b$(regex_escape_ip "${old_ipv6}")\b#${curr_ipv6}#g"
513+
for f in "${files_to_update[@]}"; do
514+
# kubernetes manifests are only present on control-plane nodes
515+
if [[ -f "$f" ]]; then
516+
sed -i "${sed_ipv6_command}" "$f"
517+
fi
518+
done
519+
fi
470520
fi
471521
if [[ -n $curr_ipv6 ]]; then
472522
echo -n "${curr_ipv6}" >/kind/old-ipv6
473523
fi
524+
525+
if $should_fix_certificate; then
526+
fix_certificate
527+
fi
474528
}
475529

476530
# validate state

pkg/drivers/kic/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424

2525
const (
2626
// Version is the current version of kic
27-
Version = "v0.0.32-1656700284-14481"
27+
Version = "v0.0.32-1659115536-14579"
2828
// SHA of the kic base image
29-
baseImageSHA = "96d18f055abcf72b9f587e13317d6f9b5bb6f60e9fa09d6c51e11defaf9bf842"
29+
baseImageSHA = "73b259e144d926189cf169ae5b46bbec4e08e4e2f2bd87296054c3244f70feb8"
3030
// The name of the GCR kicbase repository
3131
gcrRepo = "gcr.io/k8s-minikube/kicbase-builds"
3232
// The name of the Dockerhub kicbase repository

pkg/minikube/bootstrapper/images/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func KindNet(repo string) string {
182182
if repo == "" {
183183
repo = "kindest"
184184
}
185-
return path.Join(repo, "kindnetd:v20220510-4929dd75")
185+
return path.Join(repo, "kindnetd:v20220726-ed811e41")
186186
}
187187

188188
// all calico images are from https://docs.projectcalico.org/manifests/calico.yaml

site/content/en/docs/commands/start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ minikube start [flags]
2626
--apiserver-names strings A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine
2727
--apiserver-port int The apiserver listening port (default 8443)
2828
--auto-update-drivers If set, automatically updates drivers to the latest version. Defaults to true. (default true)
29-
--base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase-builds:v0.0.32-1656700284-14481@sha256:96d18f055abcf72b9f587e13317d6f9b5bb6f60e9fa09d6c51e11defaf9bf842")
29+
--base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase-builds:v0.0.32-1659115536-14579@sha256:73b259e144d926189cf169ae5b46bbec4e08e4e2f2bd87296054c3244f70feb8")
3030
--binary-mirror string Location to fetch kubectl, kubelet, & kubeadm binaries from.
3131
--cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true)
3232
--cert-expiration duration Duration until minikube certificate expiration, defaults to three years (26280h). (default 26280h0m0s)

0 commit comments

Comments
 (0)