68 lines
3.0 KiB
YAML
68 lines
3.0 KiB
YAML
# infrastructure/longhorn/core/jellyfin-volume-policy-cronjob.yaml
|
|
apiVersion: batch/v1
|
|
kind: CronJob
|
|
metadata:
|
|
name: jellyfin-volume-policy
|
|
namespace: longhorn-system
|
|
spec:
|
|
schedule: "*/10 * * * *"
|
|
concurrencyPolicy: Forbid
|
|
startingDeadlineSeconds: 30
|
|
successfulJobsHistoryLimit: 1
|
|
failedJobsHistoryLimit: 3
|
|
jobTemplate:
|
|
spec:
|
|
activeDeadlineSeconds: 120
|
|
backoffLimit: 1
|
|
ttlSecondsAfterFinished: 600
|
|
template:
|
|
spec:
|
|
serviceAccountName: longhorn-service-account
|
|
restartPolicy: Never
|
|
containers:
|
|
- name: ensure
|
|
image: bitnami/kubectl@sha256:554ab88b1858e8424c55de37ad417b16f2a0e65d1607aa0f3fe3ce9b9f10b131
|
|
command:
|
|
- /usr/bin/env
|
|
- bash
|
|
- -ceu
|
|
- |
|
|
ensure_volume() {
|
|
local pvc_name="${1}"
|
|
local replicas="${2}"
|
|
local disk_selector="${3}"
|
|
local pv_name
|
|
local volume_name
|
|
local current_replicas
|
|
local current_selector
|
|
|
|
pv_name="$(kubectl -n jellyfin get pvc "${pvc_name}" -o jsonpath='{.spec.volumeName}')"
|
|
test -n "${pv_name}"
|
|
volume_name="$(kubectl get pv "${pv_name}" -o jsonpath='{.spec.csi.volumeHandle}')"
|
|
test -n "${volume_name}"
|
|
current_replicas="$(kubectl -n longhorn-system get volumes.longhorn.io "${volume_name}" -o jsonpath='{.spec.numberOfReplicas}')"
|
|
current_selector="$(kubectl -n longhorn-system get volumes.longhorn.io "${volume_name}" -o jsonpath='{.spec.diskSelector[0]}')"
|
|
|
|
if [[ "${current_replicas}" != "${replicas}" || "${current_selector}" != "${disk_selector}" ]]; then
|
|
kubectl -n longhorn-system patch volumes.longhorn.io "${volume_name}" \
|
|
--type=merge \
|
|
--patch="{\"spec\":{\"numberOfReplicas\":${replicas},\"diskSelector\":[\"${disk_selector}\"]}}"
|
|
else
|
|
echo "${pvc_name}: ${replicas} replicas remain on ${disk_selector}"
|
|
fi
|
|
}
|
|
|
|
ensure_volume jellyfin-config-astreae 3 astreae
|
|
ensure_volume jellyfin-media-asteria-new 2 asteria
|
|
|
|
if kubectl -n longhorn-system get nodes.longhorn.io titan-22 >/dev/null 2>&1; then
|
|
allow_scheduling="$(kubectl -n longhorn-system get nodes.longhorn.io titan-22 -o jsonpath='{.spec.allowScheduling}')"
|
|
if [[ "${allow_scheduling}" != "false" ]]; then
|
|
kubectl -n longhorn-system patch nodes.longhorn.io titan-22 \
|
|
--type=merge \
|
|
--patch='{"spec":{"allowScheduling":false}}'
|
|
else
|
|
echo "titan-22: Longhorn replica scheduling remains disabled"
|
|
fi
|
|
fi
|