apiVersion: batch/v1
kind: CronJob
metadata:
  name: sre-idp-pruner
  namespace: openshift-sre-pruning
spec:
  failedJobsHistoryLimit: 5
  successfulJobsHistoryLimit: 3
  concurrencyPolicy: Replace
  schedule: "0 0 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          affinity:
            nodeAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - preference:
                  matchExpressions:
                  - key: node-role.kubernetes.io/infra
                    operator: Exists
                weight: 1
          tolerations:
            - effect: NoSchedule
              key: node-role.kubernetes.io/infra
              operator: Exists
          serviceAccountName: sre-pruner-sa
          restartPolicy: Never
          containers:
          - name: services-pruner
            image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
            imagePullPolicy: Always
            args:
            - /bin/bash
            - -c
            - >-
              oc get users | grep OpenShift_SRE | awk '{
                users[i++]=$1; for(i in users)
                {
                  print "oc delete user", users[i] 
                }}' | sh
