apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: soft-serve
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: soft-serve
  serviceName: soft-serve
  replicas: 1
  template:
    metadata:
      labels:
        app: soft-serve
    spec:
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: soft-serve
      {{ if and .Values.privateKey .Values.publicKey }}
      - name: keys
        configMap:
          name: keys
      {{ end }}
      containers:
      - name: soft-serve
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy}}
        env:
        - name: SOFT_SERVE_SSH_LISTEN_ADDR
          value: ":{{ .Values.port }}"
        - name: SOFT_SERVE_SSH_PUBLIC_URL
          value: "ssh://{{ .Values.ingress.domain }}:{{ .Values.sshPublicPort }}"
        - name: SOFT_SERVE_INITIAL_ADMIN_KEYS
          value: |-
{{ indent 12 .Values.adminKey }}
        {{ if and .Values.privateKey .Values.publicKey }}
        - name: SOFT_SERVE_SSH_KEY_PATH
          value: /.ssh/key
        {{ end }}
        - name: SOFT_SERVE_DATA_PATH
          value: /var/lib/soft-serve/repos
        - name: SOFT_SERVE_HTTP_LISTEN_ADDR
          value: ":80"
        - name: SOFT_SERVE_HTTP_PUBLIC_URL
          value: "http://{{ .Values.ingress.domain }}"
        - name: SOFT_SERVE_ALLOW_KEYLESS
          value: "{{ .Values.allowKeyless }}"
        - name: SOFT_SERVE_ANON_ACCESS
          value: "{{ .Values.anonAccess }}"
        ports:
        - name: ssh
          containerPort: {{ .Values.port }}
          protocol: TCP
        - name: http
          containerPort: 80
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /var/lib/soft-serve
          readOnly: false
        {{ if and .Values.privateKey .Values.publicKey }}
        - name: keys
          mountPath: /.ssh
          readOnly: true
        {{ end }}
