{%- set resourceName = kolla_kubernetes.template.vars.name %}

{%- if storage_provider in ["host", "ceph", "gce"] -%}

apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ resourceName }}
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: {{ kolla_kubernetes.template.vars.size_in_gb }}Gi
{%- if storage_provider == "host" %}
  hostPath:
    path: /var/lib/kolla/volumes/{{ resourceName }}

{%- elif storage_provider == "gce" %}
  gcePersistentDisk:
    pdName: {{ resourceName }}
    fsType: {{ storage_provider_fstype }}

{%- elif storage_provider == "ceph" %}
  rbd:
    monitors:
      {%- for k in storage_ceph.monitors %}
      - "{{ k }}:6789"
      {%- endfor %}
    pool: {{ storage_ceph.pool }}
    image: {{ resourceName }}
    user: {{ storage_ceph.user }}
    {%- if storage_ceph.keyring is defined and storage_ceph.keyring|length>0 %}
    keyring: {{ storage_ceph.keyring }}
    {%- endif %}
    {%- if storage_ceph.secretName is defined and storage_ceph.secretName|length>0 %}
    secretRef:
      name: {{ storage_ceph.secretName }}
    {%- endif %}
    fsType: {{ storage_provider_fstype }}
    readOnly: false
{%- endif %}

{%- elif storage_provider == "aws" %}
  # NO-OP for AWS, which supports Experimental Persistent Volume Provisioning
  # https://github.com/kubernetes/kubernetes/blob/release-1.2/examples/experimental/persistent-volume-provisioning/README.md

{%- else %}
  {{ raise('Unknown storage_provider: check kolla-kubernetes.yml:storage_provider') }}

{%- endif %}
