Skip to content

Commit 4601189

Browse files
authored
Merge pull request kubernetes#87761 from dims/ensure-specified-container-runtimes-are-present
Ensure specified container runtimes are present
2 parents a6a5fc5 + dc3f315 commit 4601189

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

cluster/gce/gci/configure.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,59 @@ function load-docker-images {
393393
fi
394394
}
395395

396+
# If we are on ubuntu we can try to install docker
397+
function install-docker {
398+
# bailout if we are not on ubuntu
399+
if ! command -v apt-get >/dev/null 2>&1; then
400+
echo "Unable to install automatically install docker. Bailing out..."
401+
return
402+
fi
403+
# Install Docker deps, some of these are already installed in the image but
404+
# that's fine since they won't re-install and we can reuse the code below
405+
# for another image someday.
406+
apt-get update
407+
apt-get install -y --no-install-recommends \
408+
apt-transport-https \
409+
ca-certificates \
410+
socat \
411+
curl \
412+
gnupg2 \
413+
software-properties-common \
414+
lsb-release
415+
416+
# Add the Docker apt-repository
417+
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg \
418+
| apt-key add -
419+
add-apt-repository \
420+
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
421+
$(lsb_release -cs) stable"
422+
423+
# Install Docker
424+
apt-get update && \
425+
apt-get install -y --no-install-recommends ${GCI_DOCKER_VERSION:-"docker-ce=5:19.03.*"}
426+
rm -rf /var/lib/apt/lists/*
427+
}
428+
429+
function ensure-container-runtime {
430+
container_runtime="${CONTAINER_RUNTIME:-docker}"
431+
if [[ "${container_runtime}" == "docker" ]]; then
432+
if ! command -v docker >/dev/null 2>&1; then
433+
install-docker
434+
if ! command -v docker >/dev/null 2>&1; then
435+
echo "ERROR docker not found. Aborting."
436+
exit 2
437+
fi
438+
fi
439+
docker version
440+
elif [[ "${container_runtime}" == "containerd" ]]; then
441+
if ! command -v ctr >/dev/null 2>&1; then
442+
echo "ERROR ctr not found. Aborting."
443+
exit 2
444+
fi
445+
ctr version
446+
fi
447+
}
448+
396449
# Downloads kubernetes binaries and kube-system manifest tarball, unpacks them,
397450
# and places them into suitable directories. Files are placed in /home/kubernetes.
398451
function install-kube-binary-config {
@@ -492,6 +545,9 @@ if [[ "${KUBERNETES_MASTER:-}" == "true" ]]; then
492545
download-kube-master-certs
493546
fi
494547

548+
# ensure chosen container runtime is present
549+
ensure-container-runtime
550+
495551
# binaries and kube-system manifests
496552
install-kube-binary-config
497553

0 commit comments

Comments
 (0)