apiVersion: apps/v1
kind: Deployment
metadata:
  name: monitor-prow-controller
  namespace: prow
  labels:
    app: monitor-prow-controller
spec:
  replicas: 1 # Do not scale up.
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: monitor-prow-controller
  template:
    metadata:
      labels:
        app: monitor-prow-controller
    spec:
      serviceAccountName: monitor-prow-controller
      terminationGracePeriodSeconds: 30
      containers:
      - name: monitor-prow-controller
        image: quay.io/powercloud/all-in-one:0.2
        command:
          - /bin/bash
        args:
          - -c
          - |
            KCTL="kubectl -n prow"
            while true;do
                date
                $KCTL logs deployment/prow-controller-manager | grep "Failed to get API Group-Resources"
                if [[ $? -eq 0 ]]; then
                    echo "prow-controller-manager got errors, restarting the deployment.."
                    $KCTL scale deployment prow-controller-manager --replicas=0
                    $KCTL scale deployment prow-controller-manager --replicas=1
                else
                    echo "prow-controller-manager deployment is in healthy state"
                fi
                sleep 300
            done
