From 90983f66e44d62582b93a64a850b5b50527091d8 Mon Sep 17 00:00:00 2001 From: varsha teratipally Date: Fri, 16 Oct 2020 16:33:26 +0000 Subject: [PATCH] Moving docker options to daemon.json As per the new docker guidelines about customizing the options like adding registry-mirrors, moving the options to daemon.json --- cluster/gce/gci/configure-helper.sh | 108 +++++++++++++++++++++------- 1 file changed, 83 insertions(+), 25 deletions(-) diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 08710e1a7d7..cdd03321b19 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -1453,6 +1453,7 @@ function create-master-etcd-apiserver-auth { fi } + function docker-installed { if systemctl cat docker.service &> /dev/null ; then return 0 @@ -1461,40 +1462,97 @@ function docker-installed { fi } +# util function to add a docker option to daemon.json file only if the daemon.json file is present. +# accepts only one argument (docker options) +function addockeropt { + DOCKER_OPTS_FILE=/etc/docker/daemon.json + if [ "$#" -lt 1 ]; then + echo "No arguments are passed while adding docker options. Expect one argument" + exit 1 + elif [ "$#" -gt 1 ]; then + echo "Only one argument is accepted" + exit 1 + fi + # appends the given input to the docker opts file i.e. /etc/docker/daemon.json file + if [ -f "$DOCKER_OPTS_FILE" ]; then + cat >> "${DOCKER_OPTS_FILE}" </etc/docker/daemon.json +{ +EOF + +addockeropt "\"pidfile\": \"/var/run/docker.pid\", + \"iptables\": false, + \"ip-masq\": false," + + echo "setting log-level" + if [[ "${TEST_CLUSTER:-}" == "true" ]]; then + addockeropt "\"log-level\": \"debug\"," + else + addockeropt "\"log-level\": \"warn\"," + fi + + echo "setting network bridge" + if [[ "${NETWORK_PROVIDER:-}" == "kubenet" || "${NETWORK_PROVIDER:-}" == "cni" ]]; then + # set docker0 cidr to private ip address range to avoid conflict with cbr0 cidr range + addockeropt "\"bip\": \"169.254.123.1/24\"," + else + addockeropt "\"bridge\": \"cbr0\"," + fi + + echo "setting registry mirror" + # TODO (vteratipally) move the registry-mirror completely to /etc/docker/daemon.json + local docker_opts="" # Decide whether to enable a docker registry mirror. This is taken from # the "kube-env" metadata value. if [[ -n "${DOCKER_REGISTRY_MIRROR_URL:-}" ]]; then - echo "Enable docker registry mirror at: ${DOCKER_REGISTRY_MIRROR_URL}" - docker_opts+=" --registry-mirror=${DOCKER_REGISTRY_MIRROR_URL}" + docker_opts+="--registry-mirror=${DOCKER_REGISTRY_MIRROR_URL} " fi + set_docker_options_non_ubuntu + + echo "setting docker logging options" # Configure docker logging - docker_opts+=" --log-driver=${DOCKER_LOG_DRIVER:-json-file}" - docker_opts+=" --log-opt=max-size=${DOCKER_LOG_MAX_SIZE:-10m}" - docker_opts+=" --log-opt=max-file=${DOCKER_LOG_MAX_FILE:-5}" - - # Disable live-restore if the environment variable is set. - - if [[ "${DISABLE_DOCKER_LIVE_RESTORE:-false}" == "true" ]]; then - docker_opts+=" --live-restore=false" - fi - - echo "DOCKER_OPTS=\"${docker_opts} ${EXTRA_DOCKER_OPTS:-}\"" > /etc/default/docker + addockeropt "\"log-driver\": \"${DOCKER_LOG_DRIVER:-json-file}\"," + addockeropt "\"log-opts\": { + \"max-size\": \"${DOCKER_LOG_MAX_SIZE:-10m}\", + \"max-file\": \"${DOCKER_LOG_MAX_FILE:-5}\" + }" + cat <>/etc/docker/daemon.json +} +EOF + echo "DOCKER_OPTS=\"${docker_opts}${EXTRA_DOCKER_OPTS:-}\"" > /etc/default/docker # Ensure TasksMax is sufficient for docker. # (https://github.com/kubernetes/kubernetes/issues/51977)