-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (37 loc) · 1.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging
from typing import Any
import kopf
from pydantic import ValidationError
from app.handlers import * # noqa: F403
from app.settings import TwingateOperatorSettings
class TwingateSmartProgressStorage(kopf.SmartProgressStorage):
def __init__(self, **kwargs):
kwargs = kwargs or {}
kwargs["name"] = "twingate"
kwargs["prefix"] = "twingate.com"
super().__init__(**kwargs)
class TwingateAnnotationsDiffBaseStorage(kopf.AnnotationsDiffBaseStorage):
def __init__(self, **kwargs):
kwargs = kwargs or {}
kwargs["prefix"] = "twingate.com"
super().__init__(**kwargs)
@kopf.on.startup()
def startup(
settings: kopf.OperatorSettings,
logger: logging.Logger | logging.LoggerAdapter,
memo: Any,
**kwargs,
):
logger.info("Operator is starting up...")
settings.persistence.finalizer = "twingate.com/finalizer"
settings.persistence.diffbase_storage = TwingateAnnotationsDiffBaseStorage()
settings.persistence.progress_storage = TwingateSmartProgressStorage()
try:
memo.twingate_settings = TwingateOperatorSettings()
except ValidationError:
logger.exception("Failed to load settings.")
# Disable health logging
logging.getLogger("aiohttp.access").setLevel(level=logging.WARNING)
@kopf.on.cleanup()
def shutdown(logger: logging.Logger | logging.LoggerAdapter, **_):
logger.info("Shutting down...")