apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "transmission.fullname" . }}
  labels:
    {{- include "transmission.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  serviceName: {{ include "transmission.fullname" . }}
  selector:
    matchLabels:
      {{- include "transmission.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "transmission.selectorLabels" . | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "transmission.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: transmission
              containerPort: 9091
              protocol: TCP
            - name: dht-tcp
              containerPort: 56451
              protocol: TCP
            - name: dht-udp
              containerPort: 56451
              protocol: UDP
          livenessProbe:
            httpGet:
              path: /
              port: 9091
          readinessProbe:
            httpGet:
              path: /
              port: 9091
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: trans-config
            mountPath: /config
          - name: trans-media
            mountPath: /media
      volumes:
      - name: trans-media
        persistentVolumeClaim:
          claimName: {{ .Values.mediaPvc }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
  volumeClaimTemplates:
  - metadata:
      name: trans-config
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: {{ .Values.config.storageClassName | quote }}
      resources:
        requests:
          storage: {{ .Values.config.storageSize }}

