-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
glusterfs.yml
92 lines (80 loc) · 3.42 KB
/
glusterfs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
- name: Get registry DeploymentConfig
oc_obj:
namespace: "{{ openshift_hosted_registry_namespace }}"
state: list
kind: dc
name: "{{ openshift_hosted_registry_name }}"
register: registry_dc
- name: Wait for registry pods
oc_obj:
namespace: "{{ openshift_hosted_registry_namespace }}"
state: list
kind: pod
selector: "{% for label, value in registry_dc.results.results[0].spec.selector.iteritems() %}{{ label }}={{ value }}{% if not loop.last %},{% endif %}{% endfor %}"
register: registry_pods
until:
- "registry_pods.results.results[0]['items'] | count > 0"
# There must be as many matching pods with 'Ready' status True as there are expected replicas
- "registry_pods.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == openshift_hosted_registry_replicas | int"
delay: 10
retries: "{{ (600 / 10) | int }}"
- name: Determine registry fsGroup
set_fact:
openshift_hosted_registry_fsgroup: "{{ registry_pods.results.results[0]['items'][0].spec.securityContext.fsGroup }}"
- name: Create temp mount directory
command: mktemp -d /tmp/openshift-glusterfs-registry-XXXXXX
register: mktemp
changed_when: False
check_mode: no
- name: Mount registry volume
mount:
state: mounted
fstype: glusterfs
src: "{% if 'glusterfs_registry' in groups %}{% set node = groups.glusterfs_registry[0] %}{% else %}{% set node = groups.glusterfs[0] %}{% endif %}{% if 'glusterfs_hostname' in hostvars[node] %}{{ hostvars[node].glusterfs_hostname }}{% elif 'openshift' in hostvars[node] %}{{ hostvars[node].openshift.node.nodename }}{% else %}{{ node }}{% endif %}:/{{ openshift.hosted.registry.storage.glusterfs.path }}"
name: "{{ mktemp.stdout }}"
- name: Set registry volume permissions
file:
dest: "{{ mktemp.stdout }}"
state: directory
group: "{{ openshift_hosted_registry_fsgroup }}"
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
name: "{{ mktemp.stdout }}"
- name: Delete temp mount directory
file:
dest: "{{ mktemp.stdout }}"
state: absent
changed_when: False
check_mode: no