{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: apps/v1alpha1
kind: PetSet
spec:
  serviceName: "rabbitmq"
  replicas: 1
  template:
    metadata:
      labels:
        service: rabbitmq
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
        pod.alpha.kubernetes.io/init-containers: '[
          {
              "name": "update-config",
              "image": "{{ kolla_toolbox_image_full }}",
              "command": [
                  "/bin/sh",
                  "-c",
                  "cp -a /srv/configmap/..data/* /srv/pod-main-config/;
                   sed -i ''/^export ERL_EPMD_ADDRESS=0.0.0.0$/d'' /srv/pod-main-config/rabbitmq-env.conf;"
              ],
              "volumeMounts": [
                  {
                      "name": "rabbitmq-config",
                      "mountPath": "/srv/configmap"
                  },
                  {
                      "name": "pod-main-config",
                      "mountPath": "/srv/pod-main-config"
                  }
              ]
          }
      ]'
    spec:
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_rabbit |
                       default(kolla_kubernetes_hostlabel_controller)
%}
          {{ selector.key }}: {{ selector.value }}
      containers:
        - image: "{{ rabbitmq_image_full }}"
          name: main
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: pod-main-config
            - mountPath: /var/lib/rabbitmq
              name: rabbitmq-persistent-storage
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
          ports:
            - containerPort: {{ rabbitmq_port }}
              name: rabbitmq
            - containerPort: {{ rabbitmq_management_port }}
              name: management
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: pod-main-config
          emptyDir: {}
        - name: rabbitmq-config
          configMap:
            name: rabbitmq
        - name: rabbitmq-persistent-storage
          persistentVolumeClaim:
            claimName: {{ resourceName }}
metadata:
   name: rabbitmq
   namespace: {{ kolla_kubernetes_namespace }}
