{%- 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: "mariadb"
  replicas: 1
  template:
    metadata:
      labels:
        service: mariadb
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_mariadb |
                       default(kolla_kubernetes_hostlabel_controller)
%}
          {{ selector.key }}: {{ selector.value }}
      terminationGracePeriodSeconds: 120 
      containers:
        - image: "{{ mariadb_image_full }}"
          name: main
          lifecycle:
            preStop:
              exec:
                command: ["mysqladmin -u {{ database_user }} -p$DATABASE_PASSWORD shutdown"]
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: mariadb-config
            - mountPath: /var/lib/mysql
              name: mariadb-persistent-storage
          env:
            - name: KOLLA_KUBERNETES
              value: ""
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: database-password
                  key: password
          ports:
            - containerPort: {{ mariadb_port }}
              name: mariadb
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: mariadb-config
          configMap:
            name: mariadb
        - name: mariadb-persistent-storage
          persistentVolumeClaim:
            claimName: {{ resourceName }}
metadata:
   name: mariadb
   namespace: {{ kolla_kubernetes_namespace }}
