add jf-detector

This commit is contained in:
ducoterra
2020-10-12 15:56:04 -04:00
parent 96d6e306af
commit 0f849f2e10
8 changed files with 76 additions and 2 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
venv/
.vscode/

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM python:latest
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY jf-detector.py ./
CMD python jf-detector.py

View File

@@ -11,6 +11,10 @@ services:
- "8080:8096" - "8080:8096"
- "8443:8920" - "8443:8920"
- "1900:1900" - "1900:1900"
jf-detector:
image: hub.ducoterra.net/ducoterra/jf-detector:0.0.4
build: .
command: sleep infinity
volumes: volumes:
jf-data: jf-data:

View File

@@ -0,0 +1,18 @@
{{ if .Values.install.jf_detector }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: jf-detector
spec:
schedule: "*/1 * * * *"
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: jf-detector
image: {{ .Values.jf_detector.image }}
restartPolicy: Never
{{ end }}

View File

@@ -12,7 +12,7 @@ spec:
app: {{ .Release.Name }} app: {{ .Release.Name }}
spec: spec:
containers: containers:
- image: jellyfin/jellyfin:10.6.4 - image: {{ .Values.jellyfin.image }}
name: jellyfin name: jellyfin
env: env:
- name: NODE_NAME - name: NODE_NAME
@@ -44,7 +44,7 @@ spec:
resources: resources:
limits: limits:
memory: "8Gi" memory: "8Gi"
cpu: "8" cpu: "4"
requests: requests:
memory: "1Mi" memory: "1Mi"
cpu: "1m" cpu: "1m"

View File

@@ -0,0 +1,8 @@
install:
jf_detector: true
jf_detector:
image: hub.ducoterra.net/ducoterra/jf-detector:0.0.4
jellyfin:
image: jellyfin/jellyfin:10.6.4

34
jf-detector.py Normal file
View File

@@ -0,0 +1,34 @@
from kubernetes import client, config
from requests.exceptions import ReadTimeout
import requests
import logging
import sys
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
try:
r = requests.get("https://jellyfin.ducoterra.net/users/public", timeout=5)
logging.info('Jellyfin up. Exiting.')
sys.exit(0)
except ReadTimeout as e:
logging.warning(e)
try:
logging.info('Trying incluster config')
config.load_incluster_config()
logging.info('Incluster config loaded')
except:
logging.info('Incluster config failed. Trying standard config')
config.load_kube_config()
logging.info('Standard config loaded')
v1 = client.CoreV1Api()
logging.info('Listing all pods in namespace ducoterra')
ret = v1.list_namespaced_pod(namespace="ducoterra")
jellyfin_pod = list(filter(lambda item: 'jellyfin' in item.metadata.name, ret.items))
logging.info(f'Found {len(jellyfin_pod)} pods')
if len(jellyfin_pod) > 0:
logging.warning('deleting jellyfin pod')
v1.delete_namespaced_pod(jellyfin_pod[0].metadata.name,'ducoterra')
else:
logging.error('no jellyfin pods found, not deleting')
sys.exit(1)

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
kubernetes==11.0.0