From 017f1a1c11725029d681694c61ef6b871e3f44bb Mon Sep 17 00:00:00 2001 From: Feilong Wang <flwang@catalyst.net.nz> Date: Wed, 8 Apr 2020 13:53:04 +1200 Subject: [PATCH] [cern][k8s] Fix docker storage of Fedora CoreOS upstream: https://review.opendev.org/c/openstack/magnum/+/718296 In commit I1a75f1bf12747508a3497293650d3cc668202de6 the worker node is missed to add the docker storage support. And the current systemd unit is not really working. So this patch fixes it by removing the hardcode for /dev/vdb and using xfs instead of ext4 (the same way for Fedora Atomic) to make it simpler and solid. Task: 39331 Story: 2005201 Change-Id: I4c465664eb19f1992df95750dd7b2d99688c6cae (cherry picked from commit c2439ca10aed0dbfa25a7e613a8105d93536db87) --- doc/source/user/index.rst | 12 +++++- ...ure_docker_storage_driver_fedora_coreos.sh | 37 +++++++++++++++++++ .../templates/kubecluster.yaml | 4 +- .../templates/kubeminion.yaml | 5 ++- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 magnum/drivers/common/templates/fragments/configure_docker_storage_driver_fedora_coreos.sh diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst index b5a812317..9609d01c4 100644 --- a/doc/source/user/index.rst +++ b/doc/source/user/index.rst @@ -1108,7 +1108,7 @@ Network driver (network-driver) `Networking`_ section for more details. Volume driver (volume-driver) - Specified in the ClusterTemplate to select the volume driver. The supported + Specified in the ClusterTemplate to select the volume driver. The supported volume driver is 'cinder', allowing Cinder volumes to be mounted in containers for use as persistent storage. Data written to these volumes will persist after the container exits and can be accessed again from other @@ -1116,10 +1116,12 @@ Volume driver (volume-driver) will be deleted. Refer to the `Storage`_ section for more details. Storage driver (docker-storage-driver) - Specified in the ClusterTemplate to select the Docker storage driver. The + Specified in the ClusterTemplate to select the Docker storage driver. The default is 'devicemapper'. Refer to the `Storage`_ section for more details. + **NOTE:** For Fedora CoreOS driver, devicemapper is not supported. + Image (image) Specified in the ClusterTemplate to indicate the image to boot the servers. The image binary is loaded in Glance with the attribute @@ -2900,6 +2902,12 @@ of Docker storage drivers available. container isolation, although it still runs in enforcing mode on the cluster compute instances. +* 'overlay2' is the preferred storage driver, for all currently supported + Linux distributions, and requires no extra configuration. When possible, + overlay2 is the recommended storage driver. When installing Docker for + the first time, overlay2 is used by default. + + Persistent storage ------------------ diff --git a/magnum/drivers/common/templates/fragments/configure_docker_storage_driver_fedora_coreos.sh b/magnum/drivers/common/templates/fragments/configure_docker_storage_driver_fedora_coreos.sh new file mode 100644 index 000000000..cca5497be --- /dev/null +++ b/magnum/drivers/common/templates/fragments/configure_docker_storage_driver_fedora_coreos.sh @@ -0,0 +1,37 @@ +ssh_cmd="ssh -F /srv/magnum/.ssh/config root@localhost" + +runtime=${CONTAINER_RUNTIME} +if [ ${CONTAINER_RUNTIME} = "containerd" ] ; then + storage_dir="/var/lib/containerd" +else + storage_dir="/var/lib/docker" + runtime="docker" +fi + +clear_docker_storage () { + # stop docker + $ssh_cmd systemctl stop ${runtime} + # clear storage graph + $ssh_cmd rm -rf ${storage_dir} + $ssh_cmd mkdir -p ${storage_dir} +} + +# Configure generic docker storage driver. +configure_storage_driver_generic() { + clear_docker_storage + + if [ -n "$DOCKER_VOLUME_SIZE" ] && [ "$DOCKER_VOLUME_SIZE" -gt 0 ]; then + $ssh_cmd mkfs.xfs -f ${device_path} + echo "${device_path} ${storage_dir} xfs defaults 0 0" >> /etc/fstab + $ssh_cmd mount -a + $ssh_cmd restorecon -R ${storage_dir} + fi + if [ ${CONTAINER_RUNTIME} = "host-docker" ] ; then + sed -i -E 's/^OPTIONS=("|'"'"')/OPTIONS=\1--storage-driver='$1' /' /etc/sysconfig/docker + fi +} + +configure_devicemapper() { + configure_storage_driver_generic +} + diff --git a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml index 0aac1870f..575d121d1 100644 --- a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml +++ b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml @@ -270,7 +270,9 @@ parameters: docker_storage_driver: type: string description: docker storage driver name - default: "devicemapper" + default: "overlay2" + constraints: + - allowed_pattern: "^(?!devicemapper$).*" cgroup_driver: type: string diff --git a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml index 36a49594b..b15a0ca53 100644 --- a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml +++ b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml @@ -502,7 +502,10 @@ resources: - get_file: ../../common/templates/fragments/configure-docker-registry.sh - get_file: ../../common/templates/kubernetes/fragments/configure-kubernetes-minion.sh - get_file: ../../common/templates/kubernetes/fragments/add-proxy.sh - # TODO add docker_storage_setup + - str_replace: + template: {get_file: ../../common/templates/fragments/configure-docker-storage.sh} + params: + $configure_docker_storage_driver: {get_file: ../../common/templates/fragments/configure_docker_storage_driver_fedora_coreos.sh} - get_file: ../../common/templates/kubernetes/fragments/enable-services-minion.sh - get_file: ../../common/templates/fragments/enable-docker-registry.sh -- GitLab