apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "danswer-stack.fullname" . }}-vespa
  labels:
    {{- include "danswer-stack.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.vespa.replicaCount }}
  selector:
    matchLabels:
      {{- include "danswer-stack.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.vespa.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "danswer-stack.labels" . | nindent 8 }}
        {{- with .Values.vespa.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "danswer-stack.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.vespa.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.vespa.securityContext | nindent 12 }}
          image: "{{ .Values.vespa.image.repository }}:{{ .Values.vespa.image.tag }}"
          imagePullPolicy: {{ .Values.vespa.image.pullPolicy }}
          ports:
            - containerPort: 19070
            - containerPort: 19071
            - containerPort: 8081
          livenessProbe:
            httpGet:
              path: /state/v1/health
              port: 19071
              scheme: HTTP
          readinessProbe:
            httpGet:
              path: /state/v1/health
              port: 19071
              scheme: HTTP
          resources:
            {{- toYaml .Values.vespa.resources | nindent 12 }}
          volumeMounts:
            - name: vespa-storage
              mountPath: /opt/vespa/var/
      {{- with .Values.vespa.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.vespa.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.vespa.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
  {{- if .Values.persistence.vespa.enabled }}
  volumeClaimTemplates:
    - metadata:
        name: vespa-storage
      spec:
        accessModes:
          {{- range .Values.persistence.vespa.accessModes }}
          - {{ . | quote }}
          {{- end }}
        resources:
          requests:
            storage: {{ .Values.persistence.vespa.size | quote }}
        {{- with .Values.persistence.vespa.storageClassName }}
        storageClassName: {{ . }}
        {{- end }}
  {{- end }}