apiVersion: batch/v1
kind: CronJob
metadata:
  labels:
    app: "producer-rss"
  name: "{{ include "producerRss.fullname" . }}-isac-uchicago-edu"
spec:
  schedule: "8 12 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          containers:
            - name: "{{ include "producerRss.fullname" . }}-isac-uchicago-edu"
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
              imagePullPolicy: "{{ .Values.image.pullPolicy }}"
              env:
                - name: API_WRITER_BACKOFF
                  value: "{{ .Values.api.writer.backoff }}"
                - name: API_WRITER_URI
                  value: "{{ .Values.api.writer.uri }}"
                - name: DB_URI
                  value: "{{ .Values.db.protocol }}://{{ .Values.db.hostname }}/?retryWrites=true&w=majority"
                - name: DB_NAME
                  value: {{ .Values.db.name }}
                - name: DB_USERNAME
                  value: {{ .Values.db.username }}
                {{- if .Values.db.password.secret.enabled }}
                - name: DB_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: "{{ .Values.db.password.secret.name }}"
                      key: "{{ .Values.db.password.secret.key }}"
                {{- else }}
                - name: DB_PASSWORD
                  value: "{{ .Values.db.password.raw }}"
                {{- end }}
                - name: DB_TABLE_NAME
                  value: {{ .Values.db.table.name }}
                - name: DB_TLS_ENABLED
                  value: "{{ .Values.db.tls.enabled }}"
                - name: DB_TLS_INSECURE
                  value: "{{ .Values.db.tls.insecure }}"
                - name: LOG_LEVEL
                  value: "{{ .Values.log.level }}"
                - name: FEED_URL
                  value: "https://isac.uchicago.edu/news.xml"
                - name: FEED_TLS_SKIP_VERIFY
                  value: "{{ .Values.feed.tls.skipVerify }}"
                - name: FEED_UPDATE_INTERVAL_MIN
                  value: "{{ .Values.feed.updateInterval.min }}"
                - name: FEED_UPDATE_INTERVAL_MAX
                  value: "{{ .Values.feed.updateInterval.max }}"
                - name: FEED_UPDATE_TIMEOUT
                  value: "{{ .Values.feed.updateTimeout }}"
                - name: FEED_USER_AGENT
                  value: "{{ .Values.feed.userAgent }}"
                - name: MSG_MD_KEY_FEED_CATEGORIES
                  value: "{{ .Values.message.metadata.key.feedCategories }}"
                - name: MSG_MD_KEY_FEED_DESCRIPTION
                  value: "{{ .Values.message.metadata.key.feedDescription }}"
                - name: MSG_MD_KEY_FEED_IMAGE_TITLE
                  value: "{{ .Values.message.metadata.key.feedImageTitle }}"
                - name: MSG_MD_KEY_FEED_IMAGE_URL
                  value: "{{ .Values.message.metadata.key.feedImageUrl }}"
                - name: MSG_MD_KEY_FEED_TITLE
                  value: "{{ .Values.message.metadata.key.feedTitle }}"
                - name: MSG_MD_KEY_AUTHOR
                  value: "{{ .Values.message.metadata.key.author }}"
                - name: MSG_MD_KEY_CATEGORIES
                  value: "{{ .Values.message.metadata.key.categories }}"
                - name: MSG_MD_KEY_GUID
                  value: "{{ .Values.message.metadata.key.guid }}"
                - name: MSG_MD_KEY_IMAGE_TITLE
                  value: "{{ .Values.message.metadata.key.imageTitle }}"
                - name: MSG_MD_KEY_IMAGE_URL
                  value: "{{ .Values.message.metadata.key.imageUrl }}"
                - name: MSG_MD_KEY_LANGUAGE
                  value: "{{ .Values.message.metadata.key.language }}"
                - name: MSG_MD_KEY_SUMMARY
                  value: "{{ .Values.message.metadata.key.summary }}"
                - name: MSG_MD_KEY_TITLE
                  value: "{{ .Values.message.metadata.key.title }}"
                - name: MSG_MD_SPEC_VERSION
                  value: "{{ .Values.message.metadata.specVersion }}"
                - name: MSG_CONTENT_TYPE
                  value: "{{ .Values.message.content.type }}"
          restartPolicy: OnFailure
