#@ load("@ytt:overlay", "overlay")

#@ ldap_ca_deployments = ["idp", "graph", "groups", "users"]

#@ for dep_name in ldap_ca_deployments:
#@overlay/match by=overlay.subset({"kind": "Deployment", "metadata": {"name": dep_name}})
---
spec:
  template:
    spec:
      volumes:
        #@overlay/match by=overlay.subset({"secret": {"secretName": "ocis-ldap-ca"}})
        #@overlay/replace
        - name: ldap-ca
          secret:
            secretName: ocis-ldap-ca-tls
            items:
              - key: tls.crt
                path: ldap-ca.crt
#@ end

#@overlay/match by=overlay.subset({"kind": "Deployment", "metadata": {"name": "idp"}})
---
spec:
  template:
    spec:
      volumes:
        #@overlay/match by=overlay.subset({"secret": {"secretName": "ocis-idp-secrets"}})
        #@overlay/replace
        - name: idp-secrets
          projected:
            sources:
              - secret:
                  name: ocis-idp-encryption
                  items:
                    - key: encryption.key
                      path: encryption.key
              - secret:
                  name: ocis-idp-rsa
                  items:
                    - key: tls.key
                      path: private-key.pem

#@overlay/match by=overlay.subset({"kind": "Deployment", "metadata": {"name": "idm"}})
---
spec:
  template:
    spec:
      volumes:
        #@overlay/match by=overlay.subset({"secret": {"secretName": "ocis-ldap-cert"}})
        #@overlay/replace
        - name: ldap-cert
          secret:
            secretName: ocis-ldap-cert-tls
            items:
              - key: tls.crt
                path: ldap.crt
              - key: tls.key
                path: ldap.key
