apiVersion: v1
kind: Template
metadata:
  name: {{ kaas_project }}-block-volumes
  annotations:
    descriptions: "{{ kaas_project }} glusterfs block volumes"
objects:
{% for name, vol in kaas_block_volumes.items() %}
{% set oc_name = vol.name | default(name) | regex_replace('_','-') %}
{% if oc_name | regex_search("^" + kaas_project) %}
{%   set pvname = oc_name %}
{% else %}
{%   set pvname = (kaas_project + "-" + oc_name) | regex_replace('_','-') %}
{% endif %}
  - apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: {{ pvname }}
    spec:
      persistentVolumeReclaimPolicy: Retain 
      accessModes:
        - ReadWriteOnce
      iscsi:
        fsType: xfs
        iqn: iqn.2016-12.org.gluster-block:{{ kaas_block_iqn[name] }}
        iscsiInterface: default
        lun: 0
        targetPortal: {{ kaas_block_portals[name][0] }}
{% if kaas_block_portals[name] | length > 1 %}
        portals: {{ kaas_block_portals[name][1:] | to_json }}
{% endif %}
      capacity:
        storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
      claimRef:
        name: {{ oc_name }}
        namespace: {{ kaas_project }}
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: {{ oc_name }}
    spec:
      volumeName: {{ pvname }}
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: {{ vol.capacity | default(kaas_default_volume_capacity) }}
{% endfor %}
