
{{- if $.Values.cronJobs.e2e.enabled }}

apiVersion: batch/v1
kind: CronJob
metadata:
  name: e2e-cron
  namespace: {{ $.Release.Namespace }}
  labels: 
    appname: oneuptime
    app.kubernetes.io/part-of: oneuptime
    app.kubernetes.io/managed-by: Helm
    {{- if $.Values.deployment.includeTimestampLabel }}
    date: "{{ now | unixEpoch }}"
    {{- end }}
spec:
  schedule: "*/30 * * * *" # At every 30 minute.
  jobTemplate:
    spec:
      template:
        spec:
          {{- if $.Values.cronJobs.e2e.nodeSelector }}
          nodeSelector:
            {{- toYaml $.Values.cronJobs.e2e.nodeSelector | nindent 12 }}
          {{- else if $.Values.nodeSelector }}
          nodeSelector:
            {{- toYaml $.Values.nodeSelector | nindent 12 }}
          {{- end }}
          containers:
          - name: e2e-cron
            image: {{ include "oneuptime.image" (dict "Values" $.Values "ServiceName" "e2e") }}
            imagePullPolicy: {{ $.Values.image.pullPolicy }}
            env:
              {{- include "oneuptime.env.common" . | nindent 14 }}
              - name: E2E_TEST_IS_USER_REGISTERED
                value: {{ $.Values.cronJobs.e2e.isUserRegistered | quote }}
              - name: E2E_TEST_REGISTERED_USER_EMAIL
                value: {{ $.Values.cronJobs.e2e.registeredUserEmail | quote }}
              - name: E2E_TEST_REGISTERED_USER_PASSWORD
                value: {{ $.Values.cronJobs.e2e.registeredUserPassword | quote }}
              - name: E2E_TEST_STATUS_PAGE_URL
                value: {{ $.Values.cronJobs.e2e.statusPageUrl | quote }}
              - name: E2E_TESTS_FAILED_WEBHOOK_URL
                value: {{ $.Values.cronJobs.e2e.failedWebhookUrl | quote }}
          restartPolicy: Never

{{- end }}