-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_deployment.py
64 lines (54 loc) · 2.2 KB
/
check_deployment.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from kubernetes import client, config
import sys
def check_deployment(namespace, deployment_name):
try:
# Carica la configurazione Kubernetes (usa il kubeconfig o in-cluster config)
config.load_kube_config()
# Crea il client API per interagire con Kubernetes
api_instance = client.AppsV1Api()
# Recupera il deployment
deployment = api_instance.read_namespaced_deployment(deployment_name, namespace)
# Flag per validazione
readiness_probe = False
liveness_probe = False
resource_requests = False
resource_limits = False
# Verifica i container del deployment
for container in deployment.spec.template.spec.containers:
# Controlla liveness probe
if container.liveness_probe:
liveness_probe = True
# Controlla readiness probe
if container.readiness_probe:
readiness_probe = True
# Controlla le risorse (Requests & Limits)
if container.resources:
if container.resources.requests:
resource_requests = True
if container.resources.limits:
resource_limits = True
# Report dei risultati
missing = []
if not readiness_probe:
missing.append("Readiness Probe")
if not liveness_probe:
missing.append("Liveness Probe")
if not resource_requests:
missing.append("Resource Requests")
if not resource_limits:
missing.append("Resource Limits")
if missing:
print(f"ERROR: Deployment '{deployment_name}' is missing: {', '.join(missing)}")
sys.exit(1)
else:
print(f"SUCCESS: Deployment '{deployment_name}' meets all best practices.")
sys.exit(0)
except client.exceptions.ApiException as e:
print(f"ERROR: Exception when calling Kubernetes API: {e}")
sys.exit(1)
if __name__ == "__main__":
# Specifica il namespace e il nome del deployment
namespace = "formazione-sou"
deployment_name = "formazione-sou-deployment"
# Esegui il controllo
check_deployment(namespace, deployment_name)