summaryrefslogtreecommitdiffstats
path: root/roles/openshift_logging/tasks/set_es_storage.yaml
blob: 0bb4d5ee52e7b3af1c651338ac4d335e3be67bc5 (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
---
- set_fact: es_storage_type="{{ es_spec.volumes['elasticsearch-storage'] }}"
  when: es_spec.volumes is defined

- set_fact: es_storage_claim="{{ es_spec.volumes['elasticsearch-storage'].persistentVolumeClaim.claimName }}"
  when:
  - es_spec.volumes is defined
  - es_storage_type.persistentVolumeClaim is defined

- set_fact: es_storage_claim=""
  when:
  - not es_spec.volumes is defined or not es_storage_type.persistentVolumeClaim is defined

## take an ES dc and evaluate its storage option
# if it is a hostmount or emptydir we don't do anything with it
# if its a pvc we see if the corresponding pvc matches the provided specs (if they exist)
- oc_obj:
    state: list
    kind: pvc
    name: "{{ es_storage_claim }}"
    namespace: "{{ openshift_logging_namespace }}"
  register: pvc_spec
  failed_when: pvc_spec.results.stderr is defined
  when:
  - es_spec.volumes is defined
  - es_storage_type.persistentVolumeClaim is defined

- set_fact: pvc_size="{{ pvc_spec.results.results[0].spec.resources.requests.storage }}"
  when:
  - pvc_spec.results is defined
  - pvc_spec.results.results[0].spec is defined

# if not create the pvc and use it
- block:

  - name: Generating PersistentVolumeClaims
    template: src=pvc.j2 dest={{mktemp.stdout}}/templates/logging-{{obj_name}}-pvc.yaml
    vars:
      obj_name: "{{ es_pvc_prefix }}-{{ es_pvc_names | count }}"
      size: "{{ es_pvc_size }}"
      access_modes: "{{ openshift_logging_storage_access_modes }}"
      pv_selector: "{{ es_pv_selector }}"
    when: not es_pvc_dynamic | bool
    check_mode: no
    changed_when: no

  - name: Generating PersistentVolumeClaims - Dynamic
    template: src=pvc.j2 dest={{mktemp.stdout}}/templates/logging-{{obj_name}}-pvc.yaml
    vars:
      obj_name: "{{ es_pvc_prefix }}-{{ es_pvc_names | count }}"
      annotations:
        volume.alpha.kubernetes.io/storage-class: "dynamic"
      size: "{{ es_pvc_size }}"
      access_modes: "{{ openshift_logging_storage_access_modes }}"
      pv_selector: "{{ es_pv_selector }}"
    when: es_pvc_dynamic | bool
    check_mode: no
    changed_when: no

  - set_fact: es_storage_claim="{{ es_pvc_prefix }}-{{ es_pvc_names | count }}"

  when:
  - es_pvc_size | search('^\d.*')
  - not es_spec.volumes is defined or not es_storage_claim | search( es_pvc_prefix ) or ( not pvc_size | search( es_pvc_size ) and not es_pvc_size | search( pvc_size ) )

- name: Generate Elasticsearch DeploymentConfig
  template: src=es.j2 dest={{mktemp.stdout}}/templates/logging-{{deploy_name}}-dc.yaml
  vars:
    component: "{{ es_component }}"
    deploy_name: "{{ es_name }}"
    logging_component: elasticsearch
    deploy_name_prefix: "logging-{{ es_component }}"
    image: "{{openshift_logging_image_prefix}}logging-elasticsearch:{{openshift_logging_image_version}}"
    es_cluster_name: "{{component}}"
    es_cpu_limit: "{{ es_cpu_limit }}"
    es_memory_limit: "{{ es_memory_limit }}"
    es_node_selector: "{{ es_node_selector }}"
    es_storage: "{{ openshift_logging_facts | es_storage( es_name, es_storage_claim ) }}"
  check_mode: no
  changed_when: no