# helm_charts_cassandra-schema-job.yaml
{{- if .Values.collector.enabled -}}
{{- if eq .Values.storage.type "cassandra" -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "jaeger.fullname" . }}-cassandra-schema
  labels:
    app.kubernetes.io/name: {{ include "jaeger.name" . }}
    helm.sh/chart: {{ include "jaeger.chart" . }}
    app.kubernetes.io/component: cassandra-schema
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Values.schema.annotations }}
  annotations:
{{ toYaml .Values.schema.annotations | indent 4 }}
{{- end }}
spec:
  activeDeadlineSeconds: {{ .Values.schema.activeDeadlineSeconds }}
  template:
    metadata:
      name: {{ include "jaeger.fullname" . }}-cassandra-schema
{{- if .Values.schema.podLabels }}
      labels:
{{ toYaml .Values.schema.podLabels | indent 8 }}
{{- end }}
    spec:
      serviceAccountName: {{ include "jaeger.fullname" . }}-cassandra-schema
      containers:
      - name: {{ include "jaeger.fullname" . }}-cassandra-schema
        image: {{ .Values.schema.image }}:{{ .Values.tag }}
        imagePullPolicy: {{ .Values.schema.pullPolicy }}
        env:
        - name: CQLSH_HOST
          value: {{ template "cassandra.host" . }}
        {{ if .Values.storage.cassandra.tls.enabled }}
        - name: CQLSH_SSL
          value: "--ssl"
        {{- end }}
        - name: MODE
          value: {{ .Values.schema.mode | quote }}
        - name: DATACENTER
          value: {{ .Values.cassandra.config.dc_name | quote }}
        - name: CASSANDRA_PORT
          value: {{ .Values.storage.cassandra.port | quote }}
        - name: CASSANDRA_USERNAME
          value: {{ .Values.storage.cassandra.user }}
        - name: CASSANDRA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ if .Values.storage.cassandra.existingSecret }}{{ .Values.storage.cassandra.existingSecret }}{{- else }}{{ include "jaeger.fullname" . }}-cassandra{{- end }}
              key: password
      {{- if .Values.schema.keyspace }}
        - name: KEYSPACE
          value: {{ .Values.schema.keyspace | quote }}
      {{- end }}
      {{- if .Values.schema.traceTtl }}
        - name: TRACE_TTL
          value: {{ .Values.schema.traceTtl | quote }}
      {{- end }}
      {{- if .Values.schema.dependenciesTtl }}
        - name: DEPENDENCIES_TTL
          value: {{ .Values.schema.dependenciesTtl | quote }}
      {{- end }}
        resources:
{{ toYaml .Values.schema.resources | indent 10 }}
        volumeMounts:
        {{- range .Values.schema.extraConfigmapMounts }}
          - name: {{ .name }}
            mountPath: {{ .mountPath }}
            subPath: {{ .subPath }}
            readOnly: {{ .readOnly }}
        {{- end }}
        {{- if .Values.storage.cassandra.tls.enabled }}
          - name: {{ .Values.storage.cassandra.tls.secretName }}
            mountPath: "/root/.cassandra/ca-cert.pem"
            subPath: "ca-cert.pem"
            readOnly: true
          - name: {{ .Values.storage.cassandra.tls.secretName }}
            mountPath: "/root/.cassandra/client-cert.pem"
            subPath: "client-cert.pem"
            readOnly: true
          - name: {{ .Values.storage.cassandra.tls.secretName }}
            mountPath: "/root/.cassandra/client-key.pem"
            subPath: "client-key.pem"
            readOnly: true
          - name: {{ .Values.storage.cassandra.tls.secretName }}
            mountPath: "/root/.cassandra/cqlshrc"
            subPath: "cqlshrc"
            readOnly: true
        {{- end }}
      restartPolicy: OnFailure
      volumes:
      {{- range .Values.schema.extraConfigmapMounts }}
        - name: {{ .name }}
          configMap:
            name: {{ .configMap }}
      {{- end }}
{{- end -}}
{{- end -}}