Skip to content

Commit

Permalink
GlusterFS: Allow swapping an existing registry's backend storage
Browse files Browse the repository at this point in the history
Signed-off-by: Jose A. Rivera <[email protected]>
  • Loading branch information
jarrpa committed May 4, 2017
1 parent 1328328 commit 4838701
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 5 deletions.
8 changes: 7 additions & 1 deletion playbooks/byo/openshift-glusterfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ registry, specify a `glusterfs_registry` group that is populated as the
`glusterfs_registry` group is specified, the cluster defined by the `glusterfs`
group will be used.

To swap an existing hosted registry's backend storage for a GlusterFS volume,
specify `openshift_hosted_registry_storage_glusterfs_swap=True`. To
additoinally copy any existing contents from an existing hosted registry,
specify `openshift_hosted_registry_storage_glusterfs_swapcopy=True`.

**NOTE:** For each namespace that is to have access to GlusterFS volumes an
Enpoints resource pointing to the GlusterFS cluster nodes and a corresponding
Service resource must be created. If dynamic provisioning using StorageClasses
Expand Down Expand Up @@ -89,4 +94,5 @@ See the documentation in the role's directory for further details.
## Role: openshift_hosted

The `openshift_hosted` role recognizes `glusterfs` as a possible storage
backend for a hosted docker registry.
backend for a hosted docker registry. It will also, if configured, handle the
swap of an existing registry's backend storage to a GlusterFS volume.
47 changes: 46 additions & 1 deletion playbooks/common/openshift-glusterfs/registry.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
---
- include: config.yml

- include: ../openshift-cluster/openshift_hosted.yml
- name: Initialize GlusterFS registry PV and PVC vars
hosts: oo_first_master
tags: hosted
tasks:
- set_fact:
glusterfs_pv: []
glusterfs_pvc: []

- set_fact:
glusterfs_pv:
- name: "{{ openshift.hosted.registry.storage.volume.name }}-glusterfs-volume"
capacity: "{{ openshift.hosted.registry.storage.volume.size }}"
access_modes: "{{ openshift.hosted.registry.storage.access.modes }}"
storage:
glusterfs:
endpoints: "{{ openshift.hosted.registry.storage.glusterfs.endpoints }}"
path: "{{ openshift.hosted.registry.storage.glusterfs.path }}"
readOnly: "{{ openshift.hosted.registry.storage.glusterfs.readOnly }}"
glusterfs_pvc:
- name: "{{ openshift.hosted.registry.storage.volume.name }}-glusterfs-claim"
capacity: "{{ openshift.hosted.registry.storage.volume.size }}"
access_modes: "{{ openshift.hosted.registry.storage.access.modes }}"
when: openshift.hosted.registry.storage.glusterfs.swap

- name: Create persistent volumes
hosts: oo_first_master
tags:
- hosted
vars:
persistent_volumes: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volumes(groups, glusterfs_pv) }}"
persistent_volume_claims: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volume_claims(glusterfs_pvc) }}"
roles:
- role: openshift_persistent_volumes
when: persistent_volumes | union(glusterfs_pv) | length > 0 or persistent_volume_claims | union(glusterfs_pvc) | length > 0

- name: Create Hosted Resources
hosts: oo_first_master
tags:
- hosted
pre_tasks:
- set_fact:
openshift_hosted_router_registryurl: "{{ hostvars[groups.oo_first_master.0].openshift.master.registry_url }}"
openshift_hosted_registry_registryurl: "{{ hostvars[groups.oo_first_master.0].openshift.master.registry_url }}"
when: "'master' in hostvars[groups.oo_first_master.0].openshift and 'registry_url' in hostvars[groups.oo_first_master.0].openshift.master"
roles:
- role: openshift_hosted
4 changes: 3 additions & 1 deletion roles/openshift_facts/library/openshift_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,9 @@ def get_defaults(self, roles, deployment_type, deployment_subtype):
glusterfs=dict(
endpoints='glusterfs-registry-endpoints',
path='glusterfs-registry-volume',
readOnly=False),
readOnly=False,
swap=False,
swapcopy=True),
host=None,
access=dict(
modes=['ReadWriteMany']
Expand Down
8 changes: 8 additions & 0 deletions roles/openshift_hosted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ From this role:
| openshift_hosted_registry_selector | region=infra | Node selector used when creating registry. The OpenShift registry will only be deployed to nodes matching this selector. |
| openshift_hosted_registry_cert_expire_days | `730` (2 years) | Validity of the certificates in days. Works only with OpenShift version 1.5 (3.5) and later. |

If you specify `openshift_hosted_registry_kind=glusterfs`, the following
variables also control configuration behavior:

| Name | Default value | Description |
|----------------------------------------------|---------------|------------------------------------------------------------------------------|
| openshift_hosted_registry_glusterfs_swap | False | Whether to swap an existing registry's storage volume for a GlusterFS volume |
| openshift_hosted_registry_glusterfs_swapcopy | True | If swapping, also copy the current contents of the registry volume |

Dependencies
------------

Expand Down
2 changes: 1 addition & 1 deletion roles/openshift_hosted/tasks/registry/registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@

- include: storage/glusterfs.yml
when:
- openshift.hosted.registry.storage.kind | default(none) == 'glusterfs'
- openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap
33 changes: 33 additions & 0 deletions roles/openshift_hosted/tasks/registry/storage/glusterfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@
mode: "2775"
recurse: True

- block:
- name: Activate registry maintenance mode
oc_env:
namespace: "{{ openshift_hosted_registry_namespace }}"
name: "{{ openshift_hosted_registry_name }}"
env_vars:
- REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED: 'true'

- name: Get first registry pod name
set_fact:
registry_pod_name: "{{ registry_pods.results.results[0]['items'][0].metadata.name }}"

- name: Copy current registry contents to new GlusterFS volume
command: "oc rsync {{ registry_pod_name }}:/registry/ {{ mktemp.stdout }}/"
when: openshift.hosted.registry.storage.glusterfs.swapcopy

- name: Swap new GlusterFS registry volume
oc_volume:
namespace: "{{ openshift_hosted_registry_namespace }}"
name: "{{ openshift_hosted_registry_name }}"
vol_name: registry-storage
mount_type: pvc
claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-glusterfs-claim"

- name: Deactivate registry maintenance mode
oc_env:
namespace: "{{ openshift_hosted_registry_namespace }}"
name: "{{ openshift_hosted_registry_name }}"
state: absent
env_vars:
- REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED: 'true'
when: openshift.hosted.registry.storage.glusterfs.swap

- name: Unmount registry volume
mount:
state: unmounted
Expand Down
7 changes: 7 additions & 0 deletions roles/openshift_storage_glusterfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ are an exception:
| openshift_storage_glusterfs_registry_namespace | registry namespace | Default is to use the hosted registry's namespace, otherwise 'default'
| openshift_storage_glusterfs_registry_nodeselector | 'storagenode=registry'| This allows for the logical separation of the registry GlusterFS cluster from any regular-use GlusterFS clusters

Additionally, this role's behavior responds to the following registry-specific
variable:

| Name | Default value | Description |
|----------------------------------------------|---------------|------------------------------------------------------------------------------|
| openshift_hosted_registry_glusterfs_swap | False | Whether to swap an existing registry's storage volume for a GlusterFS volume |

Dependencies
------------

Expand Down
2 changes: 1 addition & 1 deletion roles/openshift_storage_glusterfs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- include: glusterfs_registry.yml
when:
- g_glusterfs_registry_hosts | default([]) | count > 0
- "openshift.hosted.registry.storage.kind == 'glusterfs'"
- "openshift.hosted.registry.storage.kind == 'glusterfs' or openshift.hosted.registry.glusterfs.swap"

- name: Delete temp directory
file:
Expand Down

0 comments on commit 4838701

Please sign in to comment.