Skip to content

Commit da024f9

Browse files
committed
Ability to override versions of containerd/runc
1 parent acd286d commit da024f9

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

cluster/gce/config-default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ if [[ "${CONTAINER_RUNTIME}" == "containerd" ]]; then
101101
LOAD_IMAGE_COMMAND=${KUBE_LOAD_IMAGE_COMMAND:-ctr -n=k8s.io images import}
102102
fi
103103

104+
# Ability to inject custom versions (Ubuntu OS images ONLY)
105+
# if KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION or KUBE_UBUNTU_INSTALL_RUNC_VERSION
106+
# is set to empty then we do not override the version(s) and just
107+
# use whatever is in the default installation of containerd package
108+
UBUNTU_INSTALL_CONTAINERD_VERSION=${KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION:-}
109+
UBUNTU_INSTALL_RUNC_VERSION=${KUBE_UBUNTU_INSTALL_RUNC_VERSION:-}
110+
104111
# MASTER_EXTRA_METADATA is the extra instance metadata on master instance separated by commas.
105112
MASTER_EXTRA_METADATA=${KUBE_MASTER_EXTRA_METADATA:-${KUBE_EXTRA_METADATA:-}}
106113
# MASTER_EXTRA_METADATA is the extra instance metadata on node instance separated by commas.

cluster/gce/config-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ if [[ "${CONTAINER_RUNTIME}" == "containerd" ]]; then
107107
LOAD_IMAGE_COMMAND=${KUBE_LOAD_IMAGE_COMMAND:-ctr -n=k8s.io images import}
108108
fi
109109

110+
# Ability to inject custom versions (Ubuntu OS images ONLY)
111+
# if KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION or KUBE_UBUNTU_INSTALL_RUNC_VERSION
112+
# is set to empty then we do not override the version(s) and just
113+
# use whatever is in the default installation of containerd package
114+
UBUNTU_INSTALL_CONTAINERD_VERSION=${KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION:-}
115+
UBUNTU_INSTALL_RUNC_VERSION=${KUBE_UBUNTU_INSTALL_RUNC_VERSION:-}
116+
110117
# MASTER_EXTRA_METADATA is the extra instance metadata on master instance separated by commas.
111118
MASTER_EXTRA_METADATA=${KUBE_MASTER_EXTRA_METADATA:-${KUBE_EXTRA_METADATA:-}}
112119
# MASTER_EXTRA_METADATA is the extra instance metadata on node instance separated by commas.

cluster/gce/gci/configure.sh

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function load-docker-images {
407407
function install-docker {
408408
# bailout if we are not on ubuntu
409409
if ! command -v apt-get >/dev/null 2>&1; then
410-
echo "Unable to install automatically install docker. Bailing out..."
410+
echo "Unable to automatically install docker. Bailing out..."
411411
return
412412
fi
413413
# Install Docker deps, some of these are already installed in the image but
@@ -437,12 +437,18 @@ function install-docker {
437437
}
438438

439439
# If we are on ubuntu we can try to install containerd
440-
function install-containerd {
440+
function install-containerd-ubuntu {
441441
# bailout if we are not on ubuntu
442-
if ! command -v apt-get >/dev/null 2>&1; then
443-
echo "Unable to install automatically install docker. Bailing out..."
444-
return
442+
if [[ -z "$(command -v lsb_release)" || $(lsb_release -si) != "Ubuntu" ]]; then
443+
echo "Unable to automatically install containerd in non-ubuntu image. Bailing out..."
444+
exit 2
445445
fi
446+
447+
if [[ $(dpkg --print-architecture) != "amd64" ]]; then
448+
echo "Unable to automatically install containerd in non-amd64 image. Bailing out..."
449+
exit 2
450+
fi
451+
446452
# Install dependencies, some of these are already installed in the image but
447453
# that's fine since they won't re-install and we can reuse the code below
448454
# for another image someday.
@@ -467,6 +473,16 @@ function install-containerd {
467473
apt-get update && \
468474
apt-get install -y --no-install-recommends containerd
469475
rm -rf /var/lib/apt/lists/*
476+
477+
# Override to latest versions of containerd and runc
478+
systemctl stop containerd
479+
if [[ ! -z "${UBUNTU_INSTALL_CONTAINERD_VERSION:-}" ]]; then
480+
curl -fsSL "https://github.com/containerd/containerd/releases/download/${UBUNTU_INSTALL_CONTAINERD_VERSION}/containerd-${UBUNTU_INSTALL_CONTAINERD_VERSION:1}.linux-amd64.tar.gz" | tar --overwrite -xzv -C /usr/
481+
fi
482+
if [[ ! -z "${UBUNTU_INSTALL_RUNC_VERSION:-}" ]]; then
483+
curl -fsSL "https://github.com/opencontainers/runc/releases/download/${UBUNTU_INSTALL_RUNC_VERSION}/runc.amd64" --output /usr/sbin/runc && chmod 755 /usr/sbin/runc
484+
fi
485+
sudo systemctl start containerd
470486
}
471487

472488
function ensure-container-runtime {
@@ -481,16 +497,27 @@ function ensure-container-runtime {
481497
fi
482498
docker version
483499
elif [[ "${container_runtime}" == "containerd" ]]; then
484-
set -x
500+
# Install containerd/runc if requested
501+
if [[ ! -z "${UBUNTU_INSTALL_CONTAINERD_VERSION:-}" || ! -z "${UBUNTU_INSTALL_RUNC_VERSION}" ]]; then
502+
install-containerd-ubuntu
503+
fi
504+
# Verify presence and print versions of ctr, containerd, runc
485505
if ! command -v ctr >/dev/null 2>&1; then
486-
install-containerd
487-
if ! command -v containerd >/dev/null 2>&1; then
488-
echo "ERROR containerd not found. Aborting."
489-
exit 2
490-
fi
506+
echo "ERROR ctr not found. Aborting."
507+
exit 2
491508
fi
492509
ctr --version
510+
511+
if ! command -v containerd >/dev/null 2>&1; then
512+
echo "ERROR containerd not found. Aborting."
513+
exit 2
514+
fi
493515
containerd --version
516+
517+
if ! command -v runc >/dev/null 2>&1; then
518+
echo "ERROR runc not found. Aborting."
519+
exit 2
520+
fi
494521
runc --version
495522
fi
496523
}

cluster/gce/util.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,8 @@ DISABLE_PROMETHEUS_TO_SD_IN_DS: $(yaml-quote ${DISABLE_PROMETHEUS_TO_SD_IN_DS:-f
12241224
CONTAINER_RUNTIME: $(yaml-quote ${CONTAINER_RUNTIME:-})
12251225
CONTAINER_RUNTIME_ENDPOINT: $(yaml-quote ${CONTAINER_RUNTIME_ENDPOINT:-})
12261226
CONTAINER_RUNTIME_NAME: $(yaml-quote ${CONTAINER_RUNTIME_NAME:-})
1227+
UBUNTU_INSTALL_CONTAINERD_VERSION: $(yaml-quote ${UBUNTU_INSTALL_CONTAINERD_VERSION:-})
1228+
UBUNTU_INSTALL_RUNC_VERSION: $(yaml-quote ${UBUNTU_INSTALL_RUNC_VERSION:-})
12271229
NODE_LOCAL_SSDS_EXT: $(yaml-quote ${NODE_LOCAL_SSDS_EXT:-})
12281230
LOAD_IMAGE_COMMAND: $(yaml-quote ${LOAD_IMAGE_COMMAND:-})
12291231
ZONE: $(yaml-quote ${ZONE})

0 commit comments

Comments
 (0)