apiVersion: v1
kind: Service
metadata:
  name: jellyfin
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: jellyfin
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  namespace: {{ .Release.Namespace }}
spec:
  ingressClassName: {{ .Values.ingress.className }}
  tls:
  - hosts:
    - {{ .Values.ingress.domain }}
  rules:
  - host: {{ .Values.ingress.domain }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: jellyfin
            port:
              name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jellyfin
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: jellyfin
  replicas: 1
  template:
    metadata:
      labels:
        app: jellyfin
    spec:
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: qbittorrent-data
      - name: config
        persistentVolumeClaim:
          claimName: jellyfin-config
      - name: cache
        persistentVolumeClaim:
          claimName: jellyfin-cache
      containers:
      - name: jellyfin
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        ports:
        - name: http
          containerPort: 8096
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /data/media
          readOnly: true
        - name: config
          mountPath: /config
          readOnly: false
        - name: cache
          mountPath: /cache
          readOnly: false
        resources:
          requests:
            # memory: "10Mi"
            cpu: "2500m"
          # limits:
            # memory: "20Mi"
            # cpu: "100m"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: qbittorrent-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  volumeName: qbittorrent-data
  storageClassName: ""
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jellyfin-config
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ .Values.storage.configSize }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jellyfin-cache
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ .Values.storage.configSize }}
