Skip to content

Commit

Permalink
Merge pull request kubernetes#100157 from vteratipally/automated-cher…
Browse files Browse the repository at this point in the history
…ry-pick-of-#95655-upstream-release-1.20

Automated cherry pick of kubernetes#95655: Moving docker options to daemon.json
  • Loading branch information
k8s-ci-robot authored Apr 6, 2021
2 parents be4e504 + 0796e6c commit 7b6a5f6
Showing 1 changed file with 84 additions and 19 deletions.
103 changes: 84 additions & 19 deletions cluster/gce/gci/configure-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1452,40 +1452,105 @@ function create-master-etcd-apiserver-auth {
fi
}

function docker-installed {
if systemctl cat docker.service &> /dev/null ; then
return 0
else
return 1
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}" <<EOF
$1
EOF
fi
}

function set_docker_options_non_ubuntu() {
# set docker options mtu and storage driver for non-ubuntu
# as it is default for ubuntu
if [[ -n "$(command -v lsb_release)" && $(lsb_release -si) == "Ubuntu" ]]; then
echo "Not adding docker options on ubuntu, as these are default on ubuntu. Bailing out..."
return
fi

addockeropt "\"mtu\": 1460,"
addockeropt "\"storage-driver\": \"overlay2\","

echo "setting live restore"
# Disable live-restore if the environment variable is set.
if [[ "${DISABLE_DOCKER_LIVE_RESTORE:-false}" == "true" ]]; then
addockeropt "\"live-restore\": \"false\","
fi
}

function assemble-docker-flags {
echo "Assemble docker command line flags"
local docker_opts="-p /var/run/docker.pid --iptables=false --ip-masq=false"
echo "Assemble docker options"

# log the contents of the /etc/docker/daemon.json if already exists
if [ -f /etc/docker/daemon.json ]; then
echo "Contents of the old docker config"
cat /etc/docker/daemon.json
fi

cat <<EOF >/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
docker_opts+=" --log-level=debug"
addockeropt "\"log-level\": \"debug\","
else
docker_opts+=" --log-level=warn"
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
docker_opts+=" --bip=169.254.123.1/24"
addockeropt "\"bip\": \"169.254.123.1/24\","
else
docker_opts+=" --bridge=cbr0"
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

# 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
set_docker_options_non_ubuntu

echo "DOCKER_OPTS=\"${docker_opts} ${EXTRA_DOCKER_OPTS:-}\"" > /etc/default/docker
echo "setting docker logging options"
# Configure docker logging
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 <<EOF >>/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)
Expand Down

0 comments on commit 7b6a5f6

Please sign in to comment.