Skip to content

Commit

Permalink
Use cronjob by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hollanbm committed May 12, 2024
1 parent 44410bd commit 792e2ac
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 87 deletions.
13 changes: 11 additions & 2 deletions Docker/PlexAniSync/run/runsync.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
run() {
(cd /plexanisync && python PlexAniSync.py)
}

run_interval_loop() {
while true
do
(cd /plexanisync && python PlexAniSync.py)
run
sleep ${INTERVAL}
done
}
Expand All @@ -17,6 +21,11 @@ if [[ -z ${SETTINGS_FILE} ]]; then
run
else
echo "Using custom config: "${SETTINGS_FILE}
run

if [ ${INTERVAL} -gt 0 ]; then
run_interval_loop
else
run
fi
fi

35 changes: 19 additions & 16 deletions Helm/plexanisync/README.md

Large diffs are not rendered by default.

77 changes: 70 additions & 7 deletions Helm/plexanisync/templates/_commom.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,79 @@ Kubernetes standard labels
{{ include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $) -}}
*/}}
{{- define "common.labels.standard" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
helm.sh/chart: {{ include "common.names.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/name: {{ include "common.names.name" . | quote }}
helm.sh/chart: {{ include "common.names.chart" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
{{- end -}}

{{/*
Labels used on immutable fields such as deploy.spec.selector.matchLabels or svc.spec.selector
*/}}
{{- define "common.labels.matchLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
app.kubernetes.io/name: {{ include "common.names.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
{{- end -}}

{{- define "pod.volumes" -}}
{{- if or .Values.custom_mappings .Values.volumes }}
volumes:
{{- if .Values.custom_mappings }}
- configMap:
defaultMode: 0777
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
{{- end }}
{{- if .Values.volumes }}
{{- toYaml .Values.volumes | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}

{{- define "container.volumeMounts" -}}
{{- if or .Values.custom_mappings .Values.volumeMounts }}
volumeMounts:
{{- if .Values.custom_mappings }}
- mountPath: /plexanisync/custom_mappings.yaml
name: {{ include "common.names.fullname" . }}
subPath: custom_mappings.yaml
{{- end }}
{{- if .Values.volumeMounts }}
{{- toYaml .Values.volumeMounts | nindent 2 -}}
{{- end }}
{{- end }}
{{- end }}

{{- define "container.env" -}}
- name: PLEX_SECTION
value: {{ .Values.settings.plex_section | quote }}
- name: PLEX_URL
value: {{ .Values.settings.plex_url | required ".Values.settings.plex_url is required" | quote }}
- name: ANI_USERNAME
value: {{ .Values.settings.ani_username | required ".Values.settings.ani_username is required" | quote }}
- name: PLEX_TOKEN
valueFrom:
secretKeyRef:
key: plex-token
name: {{ include "common.names.fullname" . }}
- name: ANI_TOKEN
valueFrom:
secretKeyRef:
key: ani-token
name: {{ include "common.names.fullname" . }}
{{- if .Values.settings.plex_episode_count_priority }}
- name: PLEX_EPISODE_COUNT_PRIORITY
value: {{ .Values.settings.plex_episode_count_priority | quote }}
{{- end }}
{{- if .Values.settings.sync_ratings }}
- name: SYNC_RATINGS
value: {{ .Values.settings.sync_ratings | quote }}
{{- end }}
{{- if .Values.settings.skip_list_update }}
- name: SKIP_LIST_UPDATE
value: {{ .Values.settings.skip_list_update | quote }}
{{- end }}
{{- with .Values.envVars }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
35 changes: 35 additions & 0 deletions Helm/plexanisync/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.cronjob.enabled }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" . | nindent 4}}
spec:
concurrencyPolicy: {{ .Values.cronjob.concurrencyPolicy }}
failedJobsHistoryLimit: {{ .Values.cronjob.failedJobsHistoryLimit }}
schedule: {{ .Values.cronjob.schedule | quote }}
startingDeadlineSeconds: {{ .Values.cronjob.startingDeadlineSeconds }}
successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }}
metadata:
labels: {{- include "common.labels.standard" . | nindent 6 }}
jobTemplate:
spec:
template:
spec:
metadata:
labels: {{- include "common.labels.standard" . | nindent 14 }}
{{- with .Values.securityContext }}
securityContext: {{ toYaml . | nindent 8 -}}
{{ end }}
containers:
- env: {{- include "container.env" . | nindent 14 }}
- name: INTERVAL
value: "0"
image: {{ .Values.image }}
name: {{ include "common.names.name" . }}
resources: {{- toYaml .Values.resources | nindent 16 }}
{{- include "container.volumeMounts" . | indent 14 -}}
{{- include "pod.volumes" . | nindent 10 -}}
{{- end }}
69 changes: 8 additions & 61 deletions Helm/plexanisync/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.cronjob.enabled }}
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -16,66 +17,12 @@ spec:
securityContext: {{ toYaml . | nindent 8 -}}
{{ end }}
containers:
- env:
- name: PLEX_SECTION
value: {{ .Values.settings.plex_section }}
- name: PLEX_URL
value: {{ .Values.settings.plex_url | required ".Values.config.plex_url is required" }}
- name: ANI_USERNAME
value: {{ .Values.settings.ani_username | required ".Values.config.ani_username is required" }}
- name: PLEX_TOKEN
valueFrom:
secretKeyRef:
key: plex-token
name: {{ include "common.names.fullname" . }}
- name: ANI_TOKEN
valueFrom:
secretKeyRef:
key: ani-token
name: {{ include "common.names.fullname" . }}
{{- if .Values.settings.interval }}
- name: INTERVAL
value: {{ .Values.settings.interval | quote }}
{{- end }}
{{- if .Values.settings.plex_episode_count_priority }}
- name: PLEX_EPISODE_COUNT_PRIORITY
value: {{ .Values.settings.plex_episode_count_priority | quote }}
{{- end }}
{{- if .Values.settings.sync_ratings }}
- name: SYNC_RATINGS
value: {{ .Values.settings.sync_ratings | quote }}
{{- end }}
{{- if .Values.settings.skip_list_update }}
- name: SKIP_LIST_UPDATE
value: {{ .Values.settings.skip_list_update | quote }}
{{- end }}
{{- with .Values.envVars }}
{{- toYaml . | nindent 8 }}
{{- end }}
- env: {{- include "container.env" . | nindent 10 }}
- name: INTERVAL
value: {{ .Values.settings.interval | quote }}
image: {{ .Values.image }}
name: {{ include "common.names.name" . }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if or .Values.custom_mappings .Values.volumeMounts }}
volumeMounts:
{{- if .Values.custom_mappings }}
- mountPath: /plexanisync/custom_mappings.yaml
name: {{ include "common.names.fullname" . }}
subPath: custom_mappings.yaml
{{- end }}
{{- if .Values.volumeMounts }}
{{- toYaml .Values.volumeMounts | nindent 8 }}
{{- end }}
{{- end }}
{{- if or .Values.custom_mappings .Values.volumes }}
volumes:
{{- if .Values.custom_mappings }}
- configMap:
defaultMode: 0777
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
{{- end }}
{{- if .Values.volumes }}
{{- toYaml .Values.volumes | nindent 8 }}
{{- end }}
{{- end }}
resources: {{- toYaml .Values.resources | nindent 12 }}
{{- include "container.volumeMounts" . | indent 10 -}}
{{- include "pod.volumes" . | nindent 6 -}}
{{- end }}
12 changes: 11 additions & 1 deletion Helm/plexanisync/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ fullnameOverride:
namespaceOverride:

custom_mappings:

envVars: []

cronjob:
enabled: true
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 2
schedule: '* */1 * * *'
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1

image: ghcr.io/rickdb/plexanisync:latest

resources:
Expand All @@ -21,7 +30,8 @@ settings:
ani_username:
plex_episode_count_priority:
sync_ratings:
skip_list_update:
skip_list_update:
# interval is forced to 0 when cronjob.enabled
interval:

securityContext:
Expand Down

0 comments on commit 792e2ac

Please sign in to comment.