{{- if .Values.collector.enabled -}}
{{- if eq .Values.storage.type "cassandra" -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "jaeger.fullname" . }}-cassandra-schema
  labels:
    app: {{ template "jaeger.name" . }}
    jaeger-infra: cassandra-schema-job
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    component: cassandra-schema
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
{{- if .Values.schema.annotations }}
  annotations:
{{ toYaml .Values.schema.annotations | indent 4 }}
{{- end }}
spec:
  activeDeadlineSeconds: 120
  template:
    metadata:
      name: {{ template "jaeger.fullname" . }}-cassandra-schema
{{- if .Values.schema.podLabels }}
      labels:
{{ toYaml .Values.schema.podLabels | indent 8 }}
{{- end }}
    spec:
      containers:
      - name: {{ template "jaeger.fullname" . }}-cassandra-schema
        image: {{ .Values.schema.image }}:{{ .Values.tag }}
        imagePullPolicy: {{ .Values.schema.pullPolicy }}
        env:
        - name: CQLSH_HOST
          valueFrom:
            configMapKeyRef:
              name: {{ template "jaeger.fullname" . }}
              key: cassandra.servers
        - name: MODE
          valueFrom:
            configMapKeyRef:
              name: {{ template "jaeger.fullname" . }}
              key: cassandra.schema.mode
        - name: DATACENTER
          valueFrom:
            configMapKeyRef:
              name: {{ template "jaeger.fullname" . }}
              key: cassandra.datacenter.name
        - name: CASSANDRA_PORT
          valueFrom:
            configMapKeyRef:
              name: {{ template "jaeger.fullname" . }}
              key: cassandra.port
        resources:
{{ toYaml .Values.schema.resources | indent 10 }}
      restartPolicy: OnFailure
{{- end -}}
{{- end -}}
