-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (45 loc) · 2.16 KB
/
Copy pathmain.py
File metadata and controls
59 lines (45 loc) · 2.16 KB
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
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import kopf
import logging
import os
from prometheus_client import start_http_server
from kubernetescluster_handlers import reconcile_kubernetes_cluster, monitor_cluster_status
from clients import update_cluster_status
from metrics import init_metrics
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
print("starting NICO operator")
# --- Add Nix path to PATH ---
nix_bin_path = "/nix/var/nix/profiles/default/bin"
current_path = os.environ.get("PATH", "")
if nix_bin_path not in current_path:
os.environ["PATH"] = f"{nix_bin_path}:{current_path}"
logger.info(f"Added Nix path to PATH: {nix_bin_path}")
# KubernetesCluster handlers
@kopf.on.create("nico.homystack.com", "v1alpha1", "kubernetesclusters")
@kopf.on.update("nico.homystack.com", "v1alpha1", "kubernetesclusters")
@kopf.on.resume("nico.homystack.com", "v1alpha1", "kubernetesclusters")
@kopf.on.delete("nico.homystack.com", "v1alpha1", "kubernetesclusters")
async def unified_kubernetes_cluster_handler(body, spec, name, namespace, **kwargs):
"""Унифицированный обработчик для всех операций с KubernetesCluster"""
await reconcile_kubernetes_cluster(body, spec, name, namespace, **kwargs)
# Already defined in kubernetescluster_handlers.py, no need to redefine here
# @kopf.timer("nico.homystack.com", "v1alpha1", "kubernetesclusters", interval=30.0)
# async def monitor_cluster_status(body, spec, name, namespace, **kwargs):
# """Monitor and update cluster status based on machine states"""
# await monitor_cluster_status(body, spec, name, namespace, **kwargs)
@kopf.on.startup()
def configure(settings: kopf.OperatorSettings, **_):
settings.posting.level = logging.WARNING
# Initialize Prometheus metrics
init_metrics()
# Start Prometheus metrics server
metrics_port = int(os.environ.get("METRICS_PORT", "8080"))
try:
start_http_server(metrics_port)
logger.info(f"Prometheus metrics server started on port {metrics_port}")
except Exception as e:
logger.warning(f"Failed to start metrics server: {e}")
if __name__ == "__main__":
kopf.run()