From fe954f02f3d911e647fdb48092ed3606398a44b0 Mon Sep 17 00:00:00 2001 From: Brad Holland Date: Wed, 17 Apr 2024 01:30:42 -0400 Subject: [PATCH 1/3] Add helm chart --- .github/workflows/publish-helm-chart.yml | 34 +++++++++ Helm/plexanisync/Chart.yaml | 9 +++ Helm/plexanisync/README.md | 55 +++++++++++++++ Helm/plexanisync/templates/_commom.tpl | 62 +++++++++++++++++ Helm/plexanisync/templates/configmap.yaml | 11 +++ Helm/plexanisync/templates/deployment.yaml | 81 ++++++++++++++++++++++ Helm/plexanisync/templates/secret.yaml | 11 +++ Helm/plexanisync/values.yaml | 34 +++++++++ 8 files changed, 297 insertions(+) create mode 100644 .github/workflows/publish-helm-chart.yml create mode 100644 Helm/plexanisync/Chart.yaml create mode 100644 Helm/plexanisync/README.md create mode 100644 Helm/plexanisync/templates/_commom.tpl create mode 100644 Helm/plexanisync/templates/configmap.yaml create mode 100644 Helm/plexanisync/templates/deployment.yaml create mode 100644 Helm/plexanisync/templates/secret.yaml create mode 100644 Helm/plexanisync/values.yaml diff --git a/.github/workflows/publish-helm-chart.yml b/.github/workflows/publish-helm-chart.yml new file mode 100644 index 0000000..d9a2a7b --- /dev/null +++ b/.github/workflows/publish-helm-chart.yml @@ -0,0 +1,34 @@ +name: Release Charts + +on: + push: + branches: + - master + +jobs: + release: + # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions + # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v4.2.0 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + with: + charts_dir: Helm + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file diff --git a/Helm/plexanisync/Chart.yaml b/Helm/plexanisync/Chart.yaml new file mode 100644 index 0000000..87b437a --- /dev/null +++ b/Helm/plexanisync/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: plexanisync +version: 0.1.0 +description: Plex AniSync helm chart +type: "application" +maintainers: + - name: Brad Holland + email: hollanbm@gmail.com + url: https://www.github.com/hollanbm diff --git a/Helm/plexanisync/README.md b/Helm/plexanisync/README.md new file mode 100644 index 0000000..98e14b9 --- /dev/null +++ b/Helm/plexanisync/README.md @@ -0,0 +1,55 @@ +# plexanisync helm chart + +## 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 | `[]` | | + +### 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 + +* This chart does not provide *native* support for the following plexanisync settings. + * SETTINGS_FILE + * LOG_FAILED_MATCHES + + * It is possible to enable these features using a combination of the envVars, volumes, and volumeMounts + +#### Example values.yaml + +```yaml +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 + ani_username: UserName + plex_episode_count_priority: true + sync_ratings: false + skip_list_update: true + interval: 3600 + +tokens: + ani: ani-token + plex: plex-token + +``` diff --git a/Helm/plexanisync/templates/_commom.tpl b/Helm/plexanisync/templates/_commom.tpl new file mode 100644 index 0000000..1c69613 --- /dev/null +++ b/Helm/plexanisync/templates/_commom.tpl @@ -0,0 +1,62 @@ +{{/* +Not using enough of the bitnami common library chart, to warrant a full chart dependency +https://github.dev/bitnami/charts/blob/main/bitnami/common +*/}} + +{{/* +Expand the name of the chart. +*/}} +{{- define "common.names.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "common.names.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "common.names.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Allow the release namespace to be overridden for multi-namespace deployments in combined charts. +*/}} +{{- define "common.names.namespace" -}} +{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +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 }} +{{- 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 diff --git a/Helm/plexanisync/templates/configmap.yaml b/Helm/plexanisync/templates/configmap.yaml new file mode 100644 index 0000000..bafb1d3 --- /dev/null +++ b/Helm/plexanisync/templates/configmap.yaml @@ -0,0 +1,11 @@ +{{- if .Values.custom_mappings }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "common.names.fullname" . }} + namespace: {{ include "common.names.namespace" . }} + labels: {{- include "common.labels.standard" . | nindent 4}} +data: + custom_mappings.yaml: | + {{- .Values.custom_mappings | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/Helm/plexanisync/templates/deployment.yaml b/Helm/plexanisync/templates/deployment.yaml new file mode 100644 index 0000000..45447fc --- /dev/null +++ b/Helm/plexanisync/templates/deployment.yaml @@ -0,0 +1,81 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "common.names.fullname" . }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" . | nindent 4}} +spec: + selector: + matchLabels: {{- include "common.labels.matchLabels" . | nindent 6}} + template: + metadata: + labels: {{- include "common.labels.standard" . | nindent 8 }} + spec: + {{- with .Values.securityContext }} + 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 }} + 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 diff --git a/Helm/plexanisync/templates/secret.yaml b/Helm/plexanisync/templates/secret.yaml new file mode 100644 index 0000000..fe0acd5 --- /dev/null +++ b/Helm/plexanisync/templates/secret.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "common.names.fullname" . }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{ include "common.labels.standard" . | nindent 4}} +type: Opaque +stringData: + plex-token: {{ .Values.tokens.plex | required ".Values.tokens.plex is required" }} + ani-token: {{ .Values.tokens.ani | required ".Values.tokens.ani is required" }} diff --git a/Helm/plexanisync/values.yaml b/Helm/plexanisync/values.yaml new file mode 100644 index 0000000..52842a0 --- /dev/null +++ b/Helm/plexanisync/values.yaml @@ -0,0 +1,34 @@ +nameOverride: +fullnameOverride: +namespaceOverride: + +custom_mappings: +envVars: [] + +image: ghcr.io/rickdb/plexanisync:latest + +resources: + limits: + cpu: '1' + memory: 1Gi + requests: + cpu: 100m + memory: 256Mi + +settings: + plex_section: Anime|Anime Movies + plex_url: + ani_username: + plex_episode_count_priority: + sync_ratings: + skip_list_update: + interval: + +securityContext: + +tokens: + ani: + plex: + +volumes: [] +volumeMounts: [] \ No newline at end of file From 6187eabfaeb2a880bc5476e0d9d439a20978b75f Mon Sep 17 00:00:00 2001 From: Brad Holland Date: Sat, 11 May 2024 23:24:33 -0400 Subject: [PATCH 2/3] Use cronjob by default --- Docker/PlexAniSync/run/runsync.sh | 7 +- Helm/plexanisync/README.md | 35 +++++----- Helm/plexanisync/templates/_commom.tpl | 77 ++++++++++++++++++++-- Helm/plexanisync/templates/cronjob.yaml | 35 ++++++++++ Helm/plexanisync/templates/deployment.yaml | 69 +++---------------- Helm/plexanisync/values.yaml | 12 +++- 6 files changed, 149 insertions(+), 86 deletions(-) create mode 100644 Helm/plexanisync/templates/cronjob.yaml diff --git a/Docker/PlexAniSync/run/runsync.sh b/Docker/PlexAniSync/run/runsync.sh index 9766488..e505e69 100755 --- a/Docker/PlexAniSync/run/runsync.sh +++ b/Docker/PlexAniSync/run/runsync.sh @@ -21,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 98e14b9..588f3fb 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 1c69613..2d3cc2a 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 0000000..937fe11 --- /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 45447fc..6a03749 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 52842a0..493efb0 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: From 7d126e24e9cd9fbe2ad41c1fb50841926e4075b2 Mon Sep 17 00:00:00 2001 From: Brad Holland Date: Sun, 12 May 2024 15:21:25 -0400 Subject: [PATCH 3/3] remove deployment option from chart --- Docker/PlexAniSync/run/runsync.sh | 8 +-- Helm/plexanisync/README.md | 37 +++++------ Helm/plexanisync/templates/_commom.tpl | 63 ------------------ Helm/plexanisync/templates/cronjob.yaml | 76 +++++++++++++++++++--- Helm/plexanisync/templates/deployment.yaml | 28 -------- Helm/plexanisync/values.yaml | 9 ++- 6 files changed, 89 insertions(+), 132 deletions(-) delete mode 100644 Helm/plexanisync/templates/deployment.yaml diff --git a/Docker/PlexAniSync/run/runsync.sh b/Docker/PlexAniSync/run/runsync.sh index e505e69..7d5a8ad 100755 --- a/Docker/PlexAniSync/run/runsync.sh +++ b/Docker/PlexAniSync/run/runsync.sh @@ -21,11 +21,5 @@ if [[ -z ${SETTINGS_FILE} ]]; then run else echo "Using custom config: "${SETTINGS_FILE} - - if [ ${INTERVAL} -gt 0 ]; then - run_interval_loop - else - run - fi + run fi - diff --git a/Helm/plexanisync/README.md b/Helm/plexanisync/README.md index 588f3fb..e26996d 100644 --- a/Helm/plexanisync/README.md +++ b/Helm/plexanisync/README.md @@ -2,24 +2,23 @@ ## 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
| -| `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 * * *'` | +| 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:  
  schedule:
|
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
  schedule: "* */1 * * *"
| +| `settings.schedule` | Cron schedule, see [crontab.guru](https://crontab.guru/#*_*/1_*_*_*) for more information | `'* */1 * * *'` | +| `tokens` | plex and anilist tokens |
tokens:
  ani:
  plex:
|
tokens:
  ani: ani-token
  plex: plex-token
| +| `podSecurityContext` | [pod security context](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#securitycontext-v1-core) | `{}` | | +| `containerSecurityContext` | [container security context](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#securitycontext-v1-core) | `{}` | | +| `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:
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 2
  startingDeadlineSeconds: 300
  successfulJobsHistoryLimit: 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 @@ -49,7 +48,7 @@ settings: plex_episode_count_priority: true sync_ratings: false skip_list_update: true - interval: 3600 + schedule: "* */1 * * *" tokens: ani: ani-token diff --git a/Helm/plexanisync/templates/_commom.tpl b/Helm/plexanisync/templates/_commom.tpl index 2d3cc2a..14341dc 100644 --- a/Helm/plexanisync/templates/_commom.tpl +++ b/Helm/plexanisync/templates/_commom.tpl @@ -60,66 +60,3 @@ Labels used on immutable fields such as deploy.spec.selector.matchLabels or svc. 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 index 937fe11..2c5ab61 100644 --- a/Helm/plexanisync/templates/cronjob.yaml +++ b/Helm/plexanisync/templates/cronjob.yaml @@ -1,4 +1,3 @@ -{{- if .Values.cronjob.enabled }} --- apiVersion: batch/v1 kind: CronJob @@ -9,7 +8,7 @@ metadata: spec: concurrencyPolicy: {{ .Values.cronjob.concurrencyPolicy }} failedJobsHistoryLimit: {{ .Values.cronjob.failedJobsHistoryLimit }} - schedule: {{ .Values.cronjob.schedule | quote }} + schedule: {{ .Values.settings.schedule | quote }} startingDeadlineSeconds: {{ .Values.cronjob.startingDeadlineSeconds }} successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }} metadata: @@ -20,16 +19,73 @@ spec: spec: metadata: labels: {{- include "common.labels.standard" . | nindent 14 }} - {{- with .Values.securityContext }} + {{- with .Values.podSecurityContext }} securityContext: {{ toYaml . | nindent 8 -}} {{ end }} + restartPolicy: Never containers: - - env: {{- include "container.env" . | nindent 14 }} + - name: {{ include "common.names.name" . }} + image: {{ .Values.image }} + {{- with .Values.containerSecurityContext }} + securityContext: {{ toYaml . | nindent 14 -}} + {{ end }} + env: - 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 + - 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 }} + {{ with .Values.resources -}} + resources: {{- toYaml . | nindent 16 }} + {{- end }} + {{- 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 }} + {{- 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 }} diff --git a/Helm/plexanisync/templates/deployment.yaml b/Helm/plexanisync/templates/deployment.yaml deleted file mode 100644 index 6a03749..0000000 --- a/Helm/plexanisync/templates/deployment.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if not .Values.cronjob.enabled }} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "common.names.fullname" . }} - namespace: {{ include "common.names.namespace" . | quote }} - labels: {{- include "common.labels.standard" . | nindent 4}} -spec: - selector: - matchLabels: {{- include "common.labels.matchLabels" . | nindent 6}} - template: - metadata: - labels: {{- include "common.labels.standard" . | nindent 8 }} - spec: - {{- with .Values.securityContext }} - securityContext: {{ toYaml . | nindent 8 -}} - {{ end }} - containers: - - 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 }} - {{- 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 493efb0..9395207 100644 --- a/Helm/plexanisync/values.yaml +++ b/Helm/plexanisync/values.yaml @@ -7,10 +7,8 @@ custom_mappings: envVars: [] cronjob: - enabled: true concurrencyPolicy: Forbid failedJobsHistoryLimit: 2 - schedule: '* */1 * * *' startingDeadlineSeconds: 300 successfulJobsHistoryLimit: 1 @@ -31,10 +29,11 @@ settings: plex_episode_count_priority: sync_ratings: skip_list_update: - # interval is forced to 0 when cronjob.enabled - interval: + schedule: "* */1 * * *" -securityContext: +containerSecurityContext: + +podSecurityContext: tokens: ani: