Files
anchorhost-backend/check_longhorn.py
T
wfalkowski c177d7981d
Build and publish Docker image / build-and-publish (push) Successful in 2m45s
Refactor backend and add registry build workflow
2026-10-20 16:44:49 +00:00

37 lines
1.1 KiB
Python

"""Inspect Longhorn backup settings and targets from the active Kubernetes context."""
import json
import logging
from kubernetes import config
from kubernetes.client import ApiException, CustomObjectsApi
logger = logging.getLogger(__name__)
def main() -> int:
"""Print Longhorn settings and backup targets as JSON."""
try:
try:
config.load_incluster_config()
except config.ConfigException:
config.load_kube_config()
api = CustomObjectsApi()
settings = api.list_namespaced_custom_object(
group="longhorn.io", version="v1beta2", namespace="longhorn-system", plural="settings"
)
targets = api.list_namespaced_custom_object(
group="longhorn.io", version="v1beta2", namespace="longhorn-system", plural="backuptargets"
)
except (config.ConfigException, ApiException) as exc:
logger.error("Could not query Longhorn: %s", exc)
return 1
print(json.dumps({"settings": settings.get("items", []), "backup_targets": targets.get("items", [])}, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())