{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- set loggerConfigmapName = "cinder-volume" %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: cinder-volume-ceph
  namespace: {{ kolla_kubernetes_namespace }}
  labels:
    component: cinder-volume-ceph
    system: cinder-volume-ceph
spec:
  serviceName: "cinder"
  replicas: {{ cinder_volume_ceph_replicas }}
  template:
    metadata:
      labels:
        component: cinder-volume-ceph
        system: cinder-volume-ceph
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
          {
             "name": "initialize-config",
             "image": "{{ kolla_toolbox_image_full }}",
             "imagePullPolicy": "IfNotPresent",
             "command": [
                 "bash",
                 "-ec",
                 "cp -a /srv/configmap/..data/* /srv/pod-main-config/;
                  cp -a /srv/ceph.conf /srv/pod-main-config/;
                  cp -a /srv/ceph.client.cinder.keyring /srv/pod-main-config/;
             "],
             "volumeMounts": [
                {
                    "name": "ceph-conf",
                    "mountPath": "/srv/ceph.conf",
                    "subPath": "ceph.conf"
                },
                {
                    "name": "ceph-client-cinder-keyring",
                    "mountPath": "/srv/ceph.client.cinder.keyring",
                    "subPath": "ceph.client.cinder.keyring"
                },
                {
                   "name": "cinder-volume-configmap",
                   "mountPath": "/srv/configmap"
                },
                {
                   "name": "pod-main-config",
                   "mountPath": "/srv/pod-main-config"
                }
             ]
          },
          {
             "name": "initialize-cinder-logs",
             "image": "{{ cinder_volume_image_full }}",
             "command": [
                 "sh",
                 "-ce",
                 "mkdir /var/log/kolla/cinder ;
                  chown -R cinder: /var/log/kolla/cinder "],
             "volumeMounts": [
                {
                   "name": "kolla-logs",
                   "mountPath": "/var/log/kolla"
                }
             ]
          }
        ]'
    spec:
      hostPID: True
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_storage_ceph |
                       default(kolla_kubernetes_hostlabel_storage |
                         default(kolla_kubernetes_hostlabel_controller)
                       )
%}
          {{ selector.key }}: {{ selector.value }}
      containers:
        - image: "{{ cinder_volume_image_full }}"
          name: main
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: COPY_ALWAYS
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: pod-main-config
              readOnly: true
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: pod-main-config
          emptyDir: {}
        - name: cinder-volume-configmap
          configMap:
            name: cinder-volume
        - name: ceph-conf
          configMap:
            name: ceph-conf
        - name: ceph-client-cinder-keyring
          secret:
            secretName: ceph-client-cinder-keyring
