summaryrefslogtreecommitdiffstats
path: root/roles/openshift_storage_glusterfs/tasks/heketi_deploy_part2.yml
blob: 80aa1f2db4cf744bc70fc82932d89cb41de8a8e7 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
- name: Create heketi DB volume
  command: "heketi-cli -s http://{{ glusterfs_heketi_url }} --user admin --secret '{{ glusterfs_heketi_admin_key }}' setup-openshift-heketi-storage --listfile {{ mktemp.stdout }}/heketi-storage.json"
  register: setup_storage
  failed_when: False

# This is used in the subsequent task
- name: Copy the admin client config
  command: >
    cp {{ openshift.common.config_base }}/master/admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  changed_when: False
  check_mode: no

# Need `command` here because heketi-storage.json contains multiple objects.
- name: Copy heketi DB to GlusterFS volume
  command: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f {{ mktemp.stdout }}/heketi-storage.json -n {{ glusterfs_namespace }}"
  when: setup_storage.rc == 0

- name: Wait for copy job to finish
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    kind: job
    state: list
    name: "heketi-storage-copy-job"
  register: heketi_job
  until:
  - "'results' in heketi_job.results and heketi_job.results.results | count > 0"
  # Pod's 'Complete' status must be True
  - "heketi_job.results.results | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Complete'}) | map('bool') | select | list | count == 1"
  delay: 10
  retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  failed_when:
  - "'results' in heketi_job.results"
  - "heketi_job.results.results | count > 0"
  # Fail when pod's 'Failed' status is True
  - "heketi_job.results.results | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Failed'}) | map('bool') | select | list | count == 1"
  when: setup_storage.rc == 0

- name: Delete deploy resources
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    kind: "{{ item.kind }}"
    name: "{{ item.name | default(omit) }}"
    selector: "{{ item.selector | default(omit) }}"
    state: absent
  with_items:
  - kind: "template,route,service,jobs,dc,secret"
    selector: "deploy-heketi"
  - kind: "svc"
    name: "heketi-storage-endpoints"

- name: Generate heketi endpoints
  template:
    src: "{{ openshift.common.examples_content_version }}/heketi-endpoints.yml.j2"
    dest: "{{ mktemp.stdout }}/heketi-endpoints.yml"

- name: Generate heketi service
  template:
    src: "{{ openshift.common.examples_content_version }}/heketi-service.yml.j2"
    dest: "{{ mktemp.stdout }}/heketi-service.yml"

- name: Create heketi endpoints
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    state: present
    kind: endpoints
    name: "heketi-db-{{ glusterfs_name }}-endpoints"
    files:
    - "{{ mktemp.stdout }}/heketi-endpoints.yml"

- name: Create heketi service
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    state: present
    kind: service
    name: "heketi-db-{{ glusterfs_name }}-endpoints"
    files:
    - "{{ mktemp.stdout }}/heketi-service.yml"

- name: Copy heketi template
  copy:
    src: "{{ openshift.common.examples_content_version }}/heketi-template.yml"
    dest: "{{ mktemp.stdout }}/heketi-template.yml"

- name: Create heketi template
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    kind: template
    name: heketi
    state: present
    files:
    - "{{ mktemp.stdout }}/heketi-template.yml"

- name: Deploy heketi pod
  oc_process:
    namespace: "{{ glusterfs_namespace }}"
    template_name: "heketi"
    create: True
    params:
      IMAGE_NAME: "{{ glusterfs_heketi_image }}"
      IMAGE_VERSION: "{{ glusterfs_heketi_version }}"
      HEKETI_USER_KEY: "{{ glusterfs_heketi_user_key }}"
      HEKETI_ADMIN_KEY: "{{ glusterfs_heketi_admin_key }}"
      HEKETI_KUBE_NAMESPACE: "{{ glusterfs_namespace }}"
      CLUSTER_NAME: "{{ glusterfs_name }}"

- name: Wait for heketi pod
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    kind: pod
    state: list
    selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  register: heketi_pod
  until:
  - "heketi_pod.results.results[0]['items'] | count > 0"
  # Pod's 'Ready' status must be True
  - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == 1"
  delay: 10
  retries: "{{ (glusterfs_timeout | int / 10) | int }}"

- name: Determine heketi URL
  oc_obj:
    namespace: "{{ glusterfs_namespace }}"
    state: list
    kind: ep
    selector: "glusterfs=heketi-{{ glusterfs_name }}-service"
  register: heketi_url
  until:
  - "heketi_url.results.results[0]['items'][0].subsets[0].addresses[0].ip != ''"
  - "heketi_url.results.results[0]['items'][0].subsets[0].ports[0].port != ''"
  delay: 10
  retries: "{{ (glusterfs_timeout | int / 10) | int }}"

- name: Set heketi URL
  set_fact:
    glusterfs_heketi_url: "{{ heketi_url.results.results[0]['items'][0].subsets[0].addresses[0].ip }}:{{ heketi_url.results.results[0]['items'][0].subsets[0].ports[0].port }}"

- name: Verify heketi service
  command: "heketi-cli -s http://{{ glusterfs_heketi_url }} --user admin --secret '{{ glusterfs_heketi_admin_key }}' cluster list"
  changed_when: False