summaryrefslogtreecommitdiffstats
path: root/roles/ands_kaas/00-local-volumes.yml.j2
blob: 8d1a1c83963298cf1c9bc78578ccba78962484bc (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
---
apiVersion: v1
kind: Template
metadata:
  name: {{ kaas_project }}-local-volumes
  annotations:
    descriptions: "{{ kaas_project }} local volumes"
objects:
{% for name, vol in kaas_project_local_volumes.iteritems() %}
{%   set voltypes = kaas_storage_domains | json_query("[*].volumes." + vol.volume + ".type") %}
{%   set voltype = voltypes[0] | default('host') %}
{%   set mntpaths = kaas_storage_domains | json_query("[*].volumes." + vol.volume + ".mount") %}
{%   set mntpath = mntpaths[0] | default('') %}
{%   set oc_name = vol.name | default(name) | regex_replace('_','-') %}
{%   set cfgpath = vol.path | default("") %}
{%   set path = cfgpath if cfgpath[:1] == "/" else "/" + kaas_project + "/" + cfgpath %}
{%   if oc_name | regex_search("^" + kaas_project) %}
{%     set pvprefix = oc_name %}
{%   else %}
{%     set pvprefix = (kaas_project + "-" + oc_name) | regex_replace('_','-') %}
{%   endif %}
{%   set i = 0 %}
{%   for id in vol.nodes | default(hostvars[inventory_hostname]['ands_volume_' + vol.volume + '_server_ids']) %}
{%      set srvid = (id | string) %}
{%      set server_name = hostvars[inventory_hostname]['ands_host_' + srvid + '_public_hostname'] %}
{%      set openshift_name = hostvars[inventory_hostname]['ands_host_' + srvid + '_openshift_fqdn'] %}
{%      set pvname = pvprefix + '-' + server_name %}
{%      set pvcname = oc_name + '-' + (i|string) %}
  - apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: {{ pvname }}
      annotations:
        "volume.alpha.kubernetes.io/node-affinity": '{
            "requiredDuringSchedulingIgnoredDuringExecution": {
                "nodeSelectorTerms": [
                    { "matchExpressions": [ { "key": "kubernetes.io/hostname", "operator": "In", "values": ["{{ openshift_name }}"] } ]}
                ]
            }
        }'
    spec:
      storageClassName: kaas-local-storage
      persistentVolumeReclaimPolicy: Retain 
      local:
        path: "{{ mntpath }}{{ path }}"
        readOnly: {{ not (vol.write | default(false)) }}
      accessModes:
        - ReadWriteOnce
      capacity:
        storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
      claimRef:
        name: {{ pvcname }}
        namespace: {{ kaas_project }}
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: {{ pvcname }}
    spec:
      volumeName: {{ pvname }}
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
{%      set i = i + 1 %}
{%   endfor %}
{% endfor %}