Files
media-gitops/templates/upgrade-search.yaml
T

82 lines
3.1 KiB
YAML

{{- /*
Weekly upgrade search: makes Sonarr/Radarr actively look for better releases (in practice:
German / German DL instead of English-only files) for everything already in the library.
RSS only sees new uploads, so older episodes would otherwise never be upgraded.
- Sonarr: SeriesSearch for every monitored series. Sonarr's "Cutoff Unmet" list only looks
at quality, not at custom format scores, so CutoffUnmetEpisodeSearch would find nothing.
- Radarr: CutoffUnmetMoviesSearch (Radarr does consider CF scores) + MissingMoviesSearch.
The API keys are read at runtime from the apps' config PVCs (mounted read-only), so they
never have to be copied into a Secret or into git. Reuses the Sonarr image (curl + jq).
*/ -}}
{{- if .Values.upgradeSearch.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: upgrade-search
namespace: {{ .Values.namespace }}
labels:
app.kubernetes.io/name: upgrade-search
spec:
schedule: {{ .Values.upgradeSearch.schedule | quote }}
timeZone: {{ .Values.common.tz }}
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 2
failedJobsHistoryLimit: 2
jobTemplate:
spec:
backoffLimit: 1
ttlSecondsAfterFinished: 604800
template:
metadata:
labels:
app.kubernetes.io/name: upgrade-search
spec:
restartPolicy: Never
securityContext:
runAsUser: {{ .Values.common.puid }}
runAsGroup: {{ .Values.common.pgid }}
containers:
- name: search
image: {{ .Values.apps.sonarr.image }}
command: ["/bin/sh", "-c"]
args:
- |
set -eu
key() { sed -n 's:.*<ApiKey>\(.*\)</ApiKey>.*:\1:p' "$1"; }
cmd() { curl -sf -H "X-Api-Key: $2" -H "Content-Type: application/json" -X POST "$1/api/v3/command" -d "$3" | jq -r '"\(.name): \(.status)"'; }
S=http://sonarr:8989; SK=$(key /sonarr/config.xml)
for id in $(curl -sf -H "X-Api-Key: $SK" "$S/api/v3/series" | jq -r '.[] | select(.monitored) | .id'); do
cmd "$S" "$SK" "{\"name\":\"SeriesSearch\",\"seriesId\":$id}"
done
R=http://radarr:7878; RK=$(key /radarr/config.xml)
cmd "$R" "$RK" '{"name":"CutoffUnmetMoviesSearch"}'
cmd "$R" "$RK" '{"name":"MissingMoviesSearch"}'
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
cpu: 200m
memory: 128Mi
volumeMounts:
- name: sonarr-config
mountPath: /sonarr
readOnly: true
- name: radarr-config
mountPath: /radarr
readOnly: true
volumes:
- name: sonarr-config
persistentVolumeClaim:
claimName: sonarr-config
readOnly: true
- name: radarr-config
persistentVolumeClaim:
claimName: radarr-config
readOnly: true
{{- end }}