Files
k3s-health-dashboard/app/config.py
T
2026-04-28 13:11:31 -04:00

41 lines
1.2 KiB
Python

"""
app/config.py
Central place for all runtime configuration.
Values are read from environment variables, with sensible defaults.
Nothing in this file imports from the rest of the project.
"""
import os
from dataclasses import dataclass
@dataclass(frozen=True)
class Config:
# Kubernetes connection
in_cluster: bool # True when running as a pod inside k3s
kubeconfig: str # path to kubeconfig file (ignored if in_cluster=True)
# Dashboard behaviour
cache_ttl: int # seconds between Kubernetes API refreshes
page_title: str
page_icon: str
# Metrics
metrics_enabled: bool # set False if metrics-server is not installed
def load() -> Config:
"""
Read config from the environment.
Call once at app startup — the result is immutable.
"""
return Config(
in_cluster=os.getenv("IN_CLUSTER", "").lower() in ("1", "true", "yes"),
kubeconfig=os.getenv("KUBECONFIG", os.path.expanduser("~/.kube/config")),
cache_ttl=int(os.getenv("CACHE_TTL", "15")),
page_title=os.getenv("PAGE_TITLE", "k3s Dashboard"),
page_icon=os.getenv("PAGE_ICON", "☸️"),
metrics_enabled=os.getenv("METRICS_ENABLED", "true").lower() != "false",
)