From 620ca936bf238984ec4e368da420db532c1500e8 Mon Sep 17 00:00:00 2001 From: Idan Shamam Date: Mon, 4 Nov 2024 13:55:22 +0200 Subject: [PATCH] Healthcheck is now optional, added defaults --- deployments/sequencer/main.py | 20 ++++---------------- deployments/sequencer/services/defaults.py | 7 +++++++ deployments/sequencer/services/objects.py | 12 ++++++------ deployments/sequencer/services/service.py | 8 ++++---- 4 files changed, 21 insertions(+), 26 deletions(-) create mode 100644 deployments/sequencer/services/defaults.py diff --git a/deployments/sequencer/main.py b/deployments/sequencer/main.py index adc391e06b..159a2db70e 100644 --- a/deployments/sequencer/main.py +++ b/deployments/sequencer/main.py @@ -9,6 +9,7 @@ from services.service import Service from config.sequencer import Config, SequencerDevConfig from services.objects import Probe, HealthCheck +from services import defaults @dataclasses.dataclass @@ -39,33 +40,20 @@ def __init__( image="paulbouwer/hello-kubernetes:1.7", replicas=2, config=system_structure.config.get(), - health_check=HealthCheck( - startup_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - readiness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - liveness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5) - ) + health_check=defaults.health_check ) self.batcher = Service( self, "batcher", image="ghost", container_port=2368, - health_check=HealthCheck( - startup_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - readiness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - liveness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5) - ) + health_check=defaults.health_check ) self.sequencer_node = Service( self, "sequencer-node", image="", - container_port=8082, - health_check=HealthCheck( - startup_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - readiness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), - liveness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5) - ) + container_port=8082 ) diff --git a/deployments/sequencer/services/defaults.py b/deployments/sequencer/services/defaults.py new file mode 100644 index 0000000000..10f348f407 --- /dev/null +++ b/deployments/sequencer/services/defaults.py @@ -0,0 +1,7 @@ +from services.objects import Probe, HealthCheck + +health_check=HealthCheck( + startup_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), + readiness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5), + liveness_probe=Probe(port="http", path="/", period_seconds=5, failure_threshold=10, timeout_seconds=5) +) \ No newline at end of file diff --git a/deployments/sequencer/services/objects.py b/deployments/sequencer/services/objects.py index e4b48587da..16c5b240ed 100644 --- a/deployments/sequencer/services/objects.py +++ b/deployments/sequencer/services/objects.py @@ -1,16 +1,16 @@ import dataclasses -from typing import Union +from typing import Union, Optional from imports import k8s @dataclasses.dataclass class Probe: - port: Union[str, int] = "http" - path: str = "/" + port: Union[str, int] + path: str period_seconds: int failure_threshold: int - timeout_seconds: int = 5 + timeout_seconds: int @dataclasses.dataclass class HealthCheck: @@ -19,7 +19,7 @@ class HealthCheck: liveness_probe: Probe def __post_init__(self): - self.configure_probes() + self.get() def _create_port(self, port: Union[str, int]): return k8s.IntOrString.from_string(port) if isinstance(port, str) else k8s.IntOrString.from_number(port) @@ -35,7 +35,7 @@ def _create_k8s_probe(self, probe: Probe): timeout_seconds=probe.timeout_seconds ) - def configure_probes(self): + def get(self): self.startup_probe = self._create_k8s_probe(self.startup_probe) self.readiness_probe = self._create_k8s_probe(self.readiness_probe) self.liveness_probe = self._create_k8s_probe(self.liveness_probe) diff --git a/deployments/sequencer/services/service.py b/deployments/sequencer/services/service.py index 430538bd6c..31c8140e62 100644 --- a/deployments/sequencer/services/service.py +++ b/deployments/sequencer/services/service.py @@ -19,7 +19,7 @@ def __init__( port: Optional[int] = 80, container_port: int = 8082, config: Optional[Dict[str, str]] = None, - health_check: HealthCheck, + health_check: Optional[HealthCheck] = None, ): super().__init__(scope, id) @@ -63,9 +63,9 @@ def __init__( ports=[ k8s.ContainerPort(container_port=container_port) ], - startup_probe=health_check.startup_probe, - readiness_probe=health_check.readiness_probe, - liveness_probe=health_check.liveness_probe + startup_probe=health_check.startup_probe if health_check else None, + readiness_probe=health_check.readiness_probe if health_check else None, + liveness_probe=health_check.liveness_probe if health_check else None ) ], volumes=(