Files
media-gitops/templates/apps.yaml
T

209 lines
6.3 KiB
YAML

{{- $root := . }}
{{- range $name, $app := .Values.apps }}
{{- if $app.enabled }}
{{- $linuxserver := ne (toString $app.linuxserver) "false" }}
{{- if $app.configPath }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $name }}-config
namespace: {{ $root.Values.namespace }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
spec:
accessModes:
- ReadWriteOnce
{{- if $root.Values.storageClassName }}
storageClassName: {{ $root.Values.storageClassName }}
{{- end }}
resources:
requests:
storage: {{ $app.configSize | default "1Gi" }}
---
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $name }}
namespace: {{ $root.Values.namespace }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
spec:
replicas: 1
# RWO volumes + SQLite databases: never run two instances at once.
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: {{ $name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 8 }}
spec:
{{- if or $app.media $app.sabnzbdHostWhitelist }}
initContainers:
{{- if $app.media }}
- name: media-dirs
image: {{ $root.Values.initImage }}
command:
- sh
- -ec
- |
chown {{ $root.Values.common.puid }}:{{ $root.Values.common.pgid }} {{ $root.Values.media.mountPath }}
{{- range $root.Values.media.dirs }}
mkdir -p {{ $root.Values.media.mountPath }}/{{ . }}
chown {{ $root.Values.common.puid }}:{{ $root.Values.common.pgid }} {{ $root.Values.media.mountPath }}/{{ . }}
{{- end }}
volumeMounts:
- name: media
mountPath: {{ $root.Values.media.mountPath }}
{{- end }}
{{- if $app.sabnzbdHostWhitelist }}
- name: sabnzbd-host-whitelist
image: {{ $root.Values.initImage }}
command:
- sh
- -ec
- |
f={{ $app.configPath }}/sabnzbd.ini
hosts="{{ include "media.sabnzbdHosts" $root }}"
if [ ! -f "$f" ]; then
printf '[misc]\nhost_whitelist = %s\n' "$hosts" > "$f"
chown {{ $root.Values.common.puid }}:{{ $root.Values.common.pgid }} "$f"
echo "seeded $f"
elif ! grep -q "^host_whitelist = $hosts\$" "$f"; then
sed -i "s/^host_whitelist = .*/host_whitelist = $hosts/" "$f"
echo "updated host_whitelist in $f"
fi
volumeMounts:
- name: config
mountPath: {{ $app.configPath }}
{{- end }}
{{- end }}
containers:
- name: {{ $name }}
image: {{ $app.image }}
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: {{ $app.port }}
protocol: TCP
env:
- name: TZ
value: {{ $root.Values.common.tz | quote }}
{{- if $linuxserver }}
- name: PUID
value: {{ $root.Values.common.puid | quote }}
- name: PGID
value: {{ $root.Values.common.pgid | quote }}
{{- end }}
{{- range $app.env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
readinessProbe:
tcpSocket:
port: http
initialDelaySeconds: 10
periodSeconds: 10
livenessProbe:
tcpSocket:
port: http
initialDelaySeconds: 60
periodSeconds: 30
failureThreshold: 5
volumeMounts:
{{- if $app.configPath }}
- name: config
mountPath: {{ $app.configPath }}
{{- end }}
{{- if $app.media }}
- name: media
mountPath: {{ $root.Values.media.mountPath }}
{{- end }}
{{- /* gpu: request the iGPU from the Intel GPU device plugin (app intel-gpu-plugin
in apps-in-apps). It injects /dev/dri into the container, no privileged needed. */}}
{{- $res := deepCopy ($app.resources | default dict) }}
{{- if $app.gpu }}
{{- $_ := set $res "limits" (merge (dict "gpu.intel.com/i915" 1) (get $res "limits" | default dict)) }}
{{- end }}
{{- with $res }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if or $app.configPath $app.media }}
volumes:
{{- if $app.configPath }}
- name: config
persistentVolumeClaim:
claimName: {{ $name }}-config
{{- end }}
{{- if $app.media }}
- name: media
hostPath:
path: {{ $root.Values.media.hostPath }}
type: DirectoryOrCreate
{{- end }}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $name }}
namespace: {{ $root.Values.namespace }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: {{ $name }}
ports:
- name: http
port: {{ $app.port }}
targetPort: http
protocol: TCP
---
{{- if $app.ingress }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $name }}
namespace: {{ $root.Values.namespace }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
annotations:
cert-manager.io/cluster-issuer: {{ $root.Values.ingress.clusterIssuer }}
{{- with $root.Values.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $app.ingressAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ $root.Values.ingress.className }}
tls:
- hosts:
- {{ $name }}.{{ $root.Values.ingress.domain }}
secretName: {{ $name }}-tls
rules:
- host: {{ $name }}.{{ $root.Values.ingress.domain }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ $name }}
port:
name: http
---
{{- end }}
{{- end }}
{{- end }}