apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: increase-prometheus-storage
  namespace: openshift-monitoring
spec:
  failedJobsHistoryLimit: 5
  successfulJobsHistoryLimit: 3
  concurrencyPolicy: Forbid
  schedule: "11 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: increase-prometheus-storage
          restartPolicy: Never
          containers:
          - name: sre-build-test
            image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
            imagePullPolicy: Always
            env:
              - name: POD_NAME
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.name
              - name: POD_NS
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.namespace
            command:
            - /bin/bash
            - -c
            - |
              # ensure we fail if something exits non-zero
              set -o errexit
              set -o nounset
              set -o pipefail

              # update all pvc's which are handled by prometheus to new size
              NS=openshift-monitoring
              PVC_LIST=$(oc get pvc -n ${NS} -oname -lapp=prometheus)
              for pvc in ${PVC_LIST}; do
                oc -n ${NS} patch ${pvc} -p '{"spec":{"resources":{"requests":{"storage":"100Gi"}}}}' --type merge
              done
              # print all of the pvc's to see if the size has changed
              oc get pvc -n ${NS} -oyaml -lapp=prometheus
