# Copyright (c) 2021 SIGHUP s.r.l All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: postgres-status-check
  labels:
    app.kubernetes.io/created-by: healthcheck-controller
    kfip.sighup.io/group: Backend
    kfip.sighup.io/target: Database
    kfip.sighup.io/check: postgres-status-check
spec:
  schedule: "*/5 * * * *"
  startingDeadlineSeconds: 10 # if a job hasn't starting in this many seconds, skip
  concurrencyPolicy: Forbid # either allow|forbid|replace
  successfulJobsHistoryLimit: 3 # how many completed jobs should be
  jobTemplate:
    spec:
      activeDeadlineSeconds: 60 # job is marked failed after this limit
      template:
        metadata:
          labels:
            app.kubernetes.io/created-by: healthcheck-controller
            kfip.sighup.io/group: Backend
            kfip.sighup.io/target: Database
            kfip.sighup.io/check: postgres-status-check
        spec:
          serviceAccountName: postgres-status-check
          containers:
          - name: postgres-status-check
            image: registry.sighup.io/poc/postgres-status-check:unstable
            imagePullPolicy: Always
            envFrom:
              - configMapRef:
                  name: psc-envs
          restartPolicy: OnFailure
