From b9c515a8a5f2498cb0fd5b7879b0e2667f7fe25c Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Sun, 21 Aug 2016 19:08:44 +0100 Subject: [PATCH] Implement base container for LVM-backed CoW containers This patch implements a base container which may be used by a deployer to deploy copy-on-write container backing stores backed by LVM. This process may be used to speed up the container creation process without compromising security through the user of backing stores like overlayfs. Change-Id: I0bf227891a85bd7c8db53ca73fc5380b95e514fa --- defaults/main.yml | 9 +++++++++ ...ase-container-lvm-cow-2faa824f6cd4b083.yaml | 14 ++++++++++++++ tasks/lxc_cache_create.yml | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/base-container-lvm-cow-2faa824f6cd4b083.yaml diff --git a/defaults/main.yml b/defaults/main.yml index bfd69ce3..f88df0d9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -31,6 +31,15 @@ lxc_container_cache_path: "/var/cache/lxc/download" # which is when overlayfs was merged into the mainline kernel # lxc_container_backing_store: overlayfs +# The container backing method can be set to 'copy-on-write' to use LVM +# snapshot-backed containers when the container backing store is set to +# 'lvm'. +# lxc_container_backing_method: copy-on-write + +# When using a base container to snapshot from for the overlayfs or LVM +# copy-on-write backing stored, the base container can be set. +lxc_container_base_name: "{{ lxc_cache_map.distro }}-{{ lxc_cache_map.release }}-{{ lxc_cache_map.arch }}" + # lxc container net network lxc_net_bridge: lxcbr0 lxc_net_bridge_port: none diff --git a/releasenotes/notes/base-container-lvm-cow-2faa824f6cd4b083.yaml b/releasenotes/notes/base-container-lvm-cow-2faa824f6cd4b083.yaml new file mode 100644 index 00000000..9b96a3dd --- /dev/null +++ b/releasenotes/notes/base-container-lvm-cow-2faa824f6cd4b083.yaml @@ -0,0 +1,14 @@ +--- +features: + - The container cache preparation process now allows ``copy-on-write`` to be + set as the ``lxc_container_backing_method`` when the + ``lxc_container_backing_store`` is set to ``lvm``. When this is set a base + container will be created using a name of the form + ``-`distribution-release>`-``. + The container will be stopped as it is not used for anything except to be + a backing store for all other containers which will be based on a snapshot + of the base container. + - When using copy-on-write backing stores for containers, the base container + name may be set using the variable ``lxc_container_base_name`` which + defaults to + ``-`distribution-release>`-``. diff --git a/tasks/lxc_cache_create.yml b/tasks/lxc_cache_create.yml index 992fb179..f3b8d577 100644 --- a/tasks/lxc_cache_create.yml +++ b/tasks/lxc_cache_create.yml @@ -36,7 +36,7 @@ - name: Create base container to use for overlayfs containers lxc_container: - name: "{{ lxc_cache_map.distro }}-{{ lxc_cache_map.release }}-{{ lxc_cache_map.arch }}" + name: "{{ lxc_container_base_name }}" template: "download" state: stopped backing_store: "dir" @@ -48,3 +48,19 @@ when: - lxc_container_backing_store is defined - lxc_container_backing_store == 'overlayfs' + +- name: Create base container to use for LVM-backed copy-on-write containers + lxc_container: + name: "{{ lxc_container_base_name }}" + template: "download" + state: stopped + backing_store: "lvm" + template_options: "{{ lxc_cache_download_template_options }}" + register: cache_download + retries: 3 + delay: 10 + until: cache_download|success + when: + - lxc_container_backing_store is defined + - lxc_container_backing_store == 'lvm' + - lxc_container_backing_method == 'copy-on-write'