diff --git a/Docker/PlexAniSync/run/runsync.sh b/Docker/PlexAniSync/run/runsync.sh index 40e1a3bf..4e0f3f33 100755 --- a/Docker/PlexAniSync/run/runsync.sh +++ b/Docker/PlexAniSync/run/runsync.sh @@ -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 } @@ -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 diff --git a/Helm/plexanisync/README.md b/Helm/plexanisync/README.md index 98e14b95..588f3fb8 100644 --- a/Helm/plexanisync/README.md +++ b/Helm/plexanisync/README.md @@ -2,21 +2,24 @@ ## Values -| Name | Description | Default Value | Example | -|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `nameOverride` | String to partially override plexanisync.fullname template (will maintain the release name) | `""` | | -| `fullnameOverride` | String to fully override plexanisync.fullname template | `""` | | -| `namespaceOverride` | String to fully override common.names.namespace | `""` | | -| `custom_mappings` | Contents of custom_mappings.yaml recomended multiline yaml string. | `""` |
custom_mappings: \|
    remote-urls:
        - https://raw.githubusercontent.com/RickDB/PlexAniSync-Custom-Mappings/main/series-tvdb.en.yaml
        - https://raw.githubusercontent.com/RickDB/PlexAniSync-Custom-Mappings/main/movies-tmdb.en.yaml
| -| `envVars` | Additional EnvVars to define in the plexanisync container | `[]` |
EnvVars:
  - name: KEY
    value: "VALUE"
| -| `image` | container image to use | `ghcr.io/rickdb/plexanisync:latest` | | -| `resources` | plexanisync container resource requests/limits |
resources:
  limits:
    cpu: '1'
    memory: 1Gi
  requests:
    cpu: '100m'
    memory: 256Mi | | -| `settings` | [plexanisync environment variable settings](https://github.com/RickDB/PlexAniSync/tree/master/Docker/PlexAniSync#environment-variables) |
settings:
  plex_section: Anime\|Anime Movies
  plex_url:
  ani_username:
  plex_episode_count_priority:
  sync_ratings:
  skip_list_update:  
  interval:
|
settings:
  plex_section: Anime\|Anime Movies
  plex_url: https://plex.tld.org
  ani_username: username
  plex_episode_count_priority: true
  sync_ratings: false
  skip_list_update: true
  interval: 3600
| -| `securityContext` | [pod security context](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#securitycontext-v1-core) | `{}` | | -| `tokens` | plex and anilist tokens |
tokens:
  ani:
  plex:
|
tokens:
  ani: ani-token
  plex: plex-token
| -| `volumes` | Additional [volumes](https://kubernetes.io/docs/concepts/storage/volumes/) to define in the pod | `[]` | | -| `volumeMounts` | volumeMounts for additional volumes | `[]` | | - +| Name | Description | Default Value | Example | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `nameOverride` | String to partially override plexanisync.fullname template (will maintain the release name) | `""` | | +| `fullnameOverride` | String to fully override plexanisync.fullname template | `""` | | +| `namespaceOverride` | String to fully override common.names.namespace | `""` | | +| `custom_mappings` | Contents of custom_mappings.yaml recomended multiline yaml string. | `""` |
custom_mappings: \|
    remote-urls:
        - https://raw.githubusercontent.com/RickDB/PlexAniSync-Custom-Mappings/main/series-tvdb.en.yaml
        - https://raw.githubusercontent.com/RickDB/PlexAniSync-Custom-Mappings/main/movies-tmdb.en.yaml
| +| `envVars` | Additional EnvVars to define in the plexanisync container | `[]` |
EnvVars:
  - name: KEY
    value: "VALUE"
| +| `image` | container image to use | `ghcr.io/rickdb/plexanisync:latest` | | +| `resources` | plexanisync container resource requests/limits |
resources:
  limits:
    cpu: '1'
    memory: 1Gi
  requests:
    cpu: '100m'
    memory: 256Mi | | +| `settings` | [plexanisync environment variable settings](https://github.com/RickDB/PlexAniSync/tree/master/Docker/PlexAniSync#environment-variables) |
settings:
  plex_section: Anime\|Anime Movies
  plex_url:
  ani_username:
  plex_episode_count_priority:
  sync_ratings:
  skip_list_update:  
  interval:
|
settings:
  plex_section: Anime\|Anime Movies
  plex_url: https://plex.tld.org
  ani_username: username
  plex_episode_count_priority: true
  sync_ratings: false
  skip_list_update: true
  interval: 3600
| +| `settings.interval` | Setting only takes effect when `cronjob.enabled` = `false` | +| `securityContext` | [pod security context](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#securitycontext-v1-core) | `{}` | | +| `tokens` | plex and anilist tokens |
tokens:
  ani:
  plex:
|
tokens:
  ani: ani-token
  plex: plex-token
| +| `volumes` | Additional [volumes](https://kubernetes.io/docs/concepts/storage/volumes/) to define in the pod | `[]` | | +| `volumeMounts` | volumeMounts for additional volumes | `[]` | | +| `cronjob` | CronJob configuration, most users will most likely omit these, as the defaults should be sufficient |

cronjob:
  enabled: true
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 2
  schedule: '* */1 * * *'
  startingDeadlineSeconds: 300
  successfulJobsHistoryLimit: 1
| +| `cronjob.enabled` | When true, a cronjob will be created, when false a deployment will be used instead. | `true` | +| `cronjob.schedule` | Cron schedule, see [crontab.guru](https://crontab.guru/#*_*/1_*_*_*) for more information | `'* */1 * * *'` | ### Settings * If an optional setting is not defined, the environment variable will not be set. This will then use the plexanisync container image default for that particular setting @@ -33,12 +36,12 @@ custom_mappings: | remote-urls: - https://raw.githubusercontent.com/RickDB/PlexAniSync-Custom-Mappings/main/series-tvdb.en.yaml - entries: - title: The Rising of the Shield Hero seasons: - season: 1 anilist-id: 99263 + settings: plex_section: Anime|Anime Movies plex_url: https://plex.tld.org diff --git a/Helm/plexanisync/templates/_commom.tpl b/Helm/plexanisync/templates/_commom.tpl index 1c696139..2d3cc2ac 100644 --- a/Helm/plexanisync/templates/_commom.tpl +++ b/Helm/plexanisync/templates/_commom.tpl @@ -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 -}} \ No newline at end of file +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 }} diff --git a/Helm/plexanisync/templates/cronjob.yaml b/Helm/plexanisync/templates/cronjob.yaml new file mode 100644 index 00000000..937fe11e --- /dev/null +++ b/Helm/plexanisync/templates/cronjob.yaml @@ -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 }} \ No newline at end of file diff --git a/Helm/plexanisync/templates/deployment.yaml b/Helm/plexanisync/templates/deployment.yaml index 45447fc9..6a03749c 100644 --- a/Helm/plexanisync/templates/deployment.yaml +++ b/Helm/plexanisync/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- if not .Values.cronjob.enabled }} --- apiVersion: apps/v1 kind: Deployment @@ -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 }} \ No newline at end of file + resources: {{- toYaml .Values.resources | nindent 12 }} + {{- include "container.volumeMounts" . | indent 10 -}} + {{- include "pod.volumes" . | nindent 6 -}} +{{- end }} \ No newline at end of file diff --git a/Helm/plexanisync/values.yaml b/Helm/plexanisync/values.yaml index 52842a04..493efb02 100644 --- a/Helm/plexanisync/values.yaml +++ b/Helm/plexanisync/values.yaml @@ -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: @@ -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: