apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: openldap
  labels:
    app: openldap
spec:
  serviceName: openldap
  replicas: 1
  selector:
    matchLabels:
      app: openldap
  template:
    metadata:
      name: openldap
      labels:
        app: openldap
    spec:
      containers:
      - name: openldap
        image: mbasri/openldap:latest
        ports:
        - containerPort: 389
        - containerPort: 636
        volumeMounts:
        - name: openldap
          mountPath: /var/lib/ldap
          subPath: var/lib/ldap
        - name: openldap
          mountPath: /etc/ldap/slapd.d
          subPath: etc/ldap/slapd.d
        - name: openldap
          mountPath: /data/backup
          subPath: data/backup
        env:
        - name: LDAP_ORGANISATION
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_organisation

        - name: LDAP_DOMAIN
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_domain

        - name: LDAP_READONLY_USER
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_readonly_user
        
        - name: LDAP_BACKUP_CONFIG_CRON_EXP
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_backup_config_cron_exp

        - name: LDAP_BACKUP_DATA_CRON_EXP
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_backup_data_cron_exp

        - name: LDAP_BACKUP_TTL
          valueFrom:
            configMapKeyRef:
              name: openldap
              key: ldap_backup_ttl

        - name: LDAP_ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: openldap
              key: ldap_admin_password

        - name: LDAP_READONLY_USER_PASSWORD
          valueFrom:
            secretKeyRef:
              name: openldap
              key: ldap_readonly_password

      volumes:
      - name: openldap
        persistentVolumeClaim:
          claimName: openldap