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 fi
} }
function docker-installed { function docker-installed {
if systemctl cat docker.service &> /dev/null ; then if systemctl cat docker.service &> /dev/null ; then
return 0 return 0
@ -1461,40 +1462,97 @@ function docker-installed {
fi fi
} }
function assemble-docker-flags { # util function to add a docker option to daemon.json file only if the daemon.json file is present.
echo "Assemble docker command line flags" # accepts only one argument (docker options)
local docker_opts="-p /var/run/docker.pid --iptables=false --ip-masq=false" function addockeropt {
if [[ "${TEST_CLUSTER:-}" == "true" ]]; then DOCKER_OPTS_FILE=/etc/docker/daemon.json
docker_opts+=" --log-level=debug" if [ "$#" -lt 1 ]; then
else echo "No arguments are passed while adding docker options. Expect one argument"
docker_opts+=" --log-level=warn" exit 1
elif [ "$#" -gt 1 ]; then
echo "Only one argument is accepted"
exit 1
fi fi
if [[ "${NETWORK_PROVIDER:-}" == "kubenet" || "${NETWORK_PROVIDER:-}" == "cni" ]]; then # appends the given input to the docker opts file i.e. /etc/docker/daemon.json file
# set docker0 cidr to private ip address range to avoid conflict with cbr0 cidr range if [ -f "$DOCKER_OPTS_FILE" ]; then
docker_opts+=" --bip=169.254.123.1/24" cat >> "${DOCKER_OPTS_FILE}" <<EOF
else $1
docker_opts+=" --bridge=cbr0" 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 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 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 # Decide whether to enable a docker registry mirror. This is taken from
# the "kube-env" metadata value. # the "kube-env" metadata value.
if [[ -n "${DOCKER_REGISTRY_MIRROR_URL:-}" ]]; then 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 fi
set_docker_options_non_ubuntu
echo "setting docker logging options"
# Configure docker logging # Configure docker logging
docker_opts+=" --log-driver=${DOCKER_LOG_DRIVER:-json-file}" addockeropt "\"log-driver\": \"${DOCKER_LOG_DRIVER:-json-file}\","
docker_opts+=" --log-opt=max-size=${DOCKER_LOG_MAX_SIZE:-10m}" addockeropt "\"log-opts\": {
docker_opts+=" --log-opt=max-file=${DOCKER_LOG_MAX_FILE:-5}" \"max-size\": \"${DOCKER_LOG_MAX_SIZE:-10m}\",
\"max-file\": \"${DOCKER_LOG_MAX_FILE:-5}\"
# Disable live-restore if the environment variable is set. }"
cat <<EOF >>/etc/docker/daemon.json
if [[ "${DISABLE_DOCKER_LIVE_RESTORE:-false}" == "true" ]]; then }
docker_opts+=" --live-restore=false" EOF
fi echo "DOCKER_OPTS=\"${docker_opts}${EXTRA_DOCKER_OPTS:-}\"" > /etc/default/docker
echo "DOCKER_OPTS=\"${docker_opts} ${EXTRA_DOCKER_OPTS:-}\"" > /etc/default/docker
# Ensure TasksMax is sufficient for docker. # Ensure TasksMax is sufficient for docker.
# (https://github.com/kubernetes/kubernetes/issues/51977) # (https://github.com/kubernetes/kubernetes/issues/51977)