{{ if .Values.webapp.enabled }}

apiVersion: "sparkoperator.k8s.io/v1beta2"
kind: SparkApplication
metadata:
  name: nexus-webapp
spec:
  type: Python
  pythonVersion: "3"
  mode: cluster
  image: {{ .Values.webapp.distributed.image }}
  imagePullPolicy: Always
  mainApplicationFile: local:///incubator-sdap-nexus/analysis/webservice/webapp.py
  arguments:
    - --cassandra-host={{ include "nexus.urls.cassandra" . }}
    - --cassandra-username={{ include "nexus.credentials.cassandra.username" . }}
    - --cassandra-password={{ include "nexus.credentials.cassandra.password" . }}
    - --solr-host={{ include "nexus.urls.solr" . }}
    - --collections-path={{ include "nexus.collectionsConfig.mountPath" . }}/collections.yml
  sparkVersion: "3.1.1"
  volumes:
    - name: collections-config-volume
      configMap:
        name: {{ include "nexus.collectionsConfig.configmapName" . }}
  restartPolicy:
    type: OnFailure
    onFailureRetries: 10
    onFailureRetryInterval: 10
    onSubmissionFailureRetries: 10
    onSubmissionFailureRetryInterval: 10
  driver:
    volumeMounts:
      - name: collections-config-volume
        mountPath: {{ include "nexus.collectionsConfig.mountPath" . }}
{{ .Values.webapp.distributed.driver | toYaml | indent 4 }}
    labels:
      version: 3.1.1
    serviceAccount: spark-serviceaccount
  executor:
{{ .Values.webapp.distributed.executor| toYaml | indent 4 }}
    labels:
      version: 3.1.1

---

apiVersion: v1
kind: Service
metadata:
  name: nexus-webapp
spec:
  selector:
    spark-role: driver
    sparkoperator.k8s.io/app-name: nexus-webapp
  type: ClusterIP
  ports:
  - name: webapp
    protocol: TCP
    port: 8083
    targetPort: 8083

{{ end }}
