34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
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) |