Skip to content

Commit

Permalink
Healthcheck is now optional, added defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-starkware committed Nov 4, 2024
1 parent 34d315e commit 620ca93
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
20 changes: 4 additions & 16 deletions deployments/sequencer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)


Expand Down
7 changes: 7 additions & 0 deletions deployments/sequencer/services/defaults.py
Original file line number Diff line number Diff line change
@@ -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)
)
12 changes: 6 additions & 6 deletions deployments/sequencer/services/objects.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
Expand All @@ -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)
8 changes: 4 additions & 4 deletions deployments/sequencer/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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=(
Expand Down

0 comments on commit 620ca93

Please sign in to comment.