apiVersion: batch/v1
kind: CronJob
metadata:
  name: github-ldap-mapping-update
  namespace: ocp-test-platform
spec:
  schedule: "0 1 * * *" # 1 AM every day
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: github-ldap-mapping-update
            image: registry.ci.openshift.org/ci/ldap-users-from-github-owners-files:latest
            imagePullPolicy: Always
            args:
            - -c
            - |
              set -euo pipefail
              set -x
              rm -f /tmp/mapping.yaml
              ldapsearch -LLL -x -h ldap.corp.redhat.com -b ou=users,dc=redhat,dc=com '(rhatSocialURL=GitHub*)' rhatSocialURL uid 2>&1 | tee /tmp/out
              ldap-users-from-github-owners-files --ldap-file /tmp/out --mapping-file /tmp/mapping.yaml
              export KUBECONFIG=/etc/kube/sa.github-ldap-mapping-updater.app.ci.config
              oc -n ci create configmap github-ldap-mapping --from-file=mapping.yaml=/tmp/mapping.yaml --dry-run=client -o yaml | oc -n ci apply -f -
            command:
            - /bin/bash
            volumeMounts:
            - name: kube
              mountPath: "/etc/kube"
              readOnly: true
          restartPolicy: OnFailure
          volumes:
          - name: kube
            secret:
              secretName: github-ldap-mapping-updater-credentials
