Merge pull request #95655 from vteratipally/docker_daemon_json

Moving docker options to daemon.json
This commit is contained in:
Kubernetes Prow Robot 2021-03-10 15:00:23 -08:00 committed by GitHub
commit a5b5a685ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}" <<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"
if [[ "${TEST_CLUSTER:-}" == "true" ]]; then
docker_opts+=" --log-level=debug"
else
docker_opts+=" --log-level=warn"
fi
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"
else
docker_opts+=" --bridge=cbr0"
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
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 <<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)