apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: deployment-restart
spec:
  concurrencyPolicy: Forbid
  schedule: '0 0 * * *'
  # schedule: '*/3 * * * *' #only for testing
  jobTemplate:
    spec:
      backoffLimit: 2
      activeDeadlineSeconds: 600 # timeout
                                
      template:
        spec:
          serviceAccountName: deployment-restart # name of the service
                                                 # account configured above
          restartPolicy: Never
          containers:
            - name: kubectl
              image: quay.io/bitnami/kubectl:1.20
              env:
                - name: REGISTRY_DEPLOYMENT_NAME
                  value: apicurio-registry-mt
                - name: UI_DEPLOYMENT_NAME
                  value: apicurio-registry-mt-ui-mt
              command:
                - bash
                - -c
                - >-
                  kubectl rollout restart deployment/$REGISTRY_DEPLOYMENT_NAME &&
                  kubectl rollout status deployment/$REGISTRY_DEPLOYMENT_NAME &&
                  kubectl rollout restart deployment/$UI_DEPLOYMENT_NAME &&
                  kubectl rollout status deployment/$UI_DEPLOYMENT_NAME