apiVersion: batch/v1
kind: CronJob
metadata:
  name: restart-teleport-proxy
spec:
  concurrencyPolicy: Forbid
  schedule: "@monthly"
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: restarter
          containers:
          - name: ubuntu
            image: quay.io/cybozu/ubuntu:20.04
            imagePullPolicy: IfNotPresent
            command:
              - /bin/sh
              - -c
              - |
                TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token);
                curl -isSk -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/strategic-merge-patch+json" https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_PORT_443_TCP_PORT}/apis/apps/v1/namespaces/teleport/deployments/teleport-proxy/ -X PATCH --data '{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubrnetes.io/restartedAt":"'"$(date +%Y-%m-%dT%T%z)"'"}}}}}'
          restartPolicy: OnFailure
          securityContext:
            runAsUser: 10000
            runAsGroup: 10000
