Skip to content

Commit

Permalink
chore(deployment): added const
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-starkware committed Nov 25, 2024
1 parent d2d18ba commit 0bfc1fe
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 44 deletions.
4 changes: 2 additions & 2 deletions deployments/sequencer/app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def __init__(
self.namespace = namespace
self.label = {"app": Names.to_label_value(self, include_hash=False)}
self.topology = topology

self.set_k8s_namespace()

if topology.port_mappings is not None:
if topology.service is not None:
self.set_k8s_service()

if topology.config is not None:
Expand Down
14 changes: 14 additions & 0 deletions deployments/sequencer/services/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# k8s service types
CLUSTER_IP = "ClusterIP"
LOAD_BALANCER = "LoadBalancer"
NODE_PORT = "NodePort"

# k8s container ports
HTTP_CONTAINER_PORT = 8080
RPC_CONTAINER_PORT = 8081
MONITORING_CONTAINER_PORT = 8082

# k8s service ports
HTTP_SERVICE_PORT = 80
RPC_SERVICE_PORT = 8081
MONITORING_SERVICE_PORT = 8082
19 changes: 1 addition & 18 deletions deployments/sequencer/services/objects.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import dataclasses

from typing import Optional, List, Dict, Any, Mapping, Sequence
from enum import Enum
from imports import k8s
from cdk8s import Names


@dataclasses.dataclass
Expand All @@ -26,16 +22,9 @@ class PortMapping:
container_port: int


@dataclasses.dataclass
class ServiceType(Enum):
CLUSTER_IP = "ClusterIP"
LOAD_BALANCER = "LoadBalancer"
NODE_PORT = "NodePort"


@dataclasses.dataclass
class Service:
type: Optional[ServiceType]
type: Optional[str]
selector: Mapping[str, str]
ports: Sequence[PortMapping]

Expand Down Expand Up @@ -99,12 +88,6 @@ class VolumeMount:
read_only: bool


@dataclasses.dataclass
class VolumeType(Enum):
CONFIG_MAP = "ConfigMap"
PERSISTENT_VOLUME_CLAIM = "PersistentVolumeClaim"


@dataclasses.dataclass
class ConfigMapVolume:
name: str
Expand Down
1 change: 0 additions & 1 deletion deployments/sequencer/services/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ServiceTopology:
deployment: typing.Optional[objects.Deployment] = dataclasses.field(default_factory=topology_helpers.get_deployment)
config: typing.Optional[objects.Config] = dataclasses.field(default_factory=topology_helpers.get_config)
service: typing.Optional[objects.Service] = dataclasses.field(default_factory=topology_helpers.get_service)
port_mappings: typing.Optional[typing.Sequence[objects.PortMapping]] = dataclasses.field(default_factory=topology_helpers.get_port_mappings)
pvc: typing.Optional[objects.PersistentVolumeClaim] = dataclasses.field(default_factory=topology_helpers.get_pvc)
ingress: typing.Optional[objects.Ingress] = dataclasses.field(default_factory=topology_helpers.get_ingress)

Expand Down
38 changes: 15 additions & 23 deletions deployments/sequencer/services/topology_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
import const

from services import objects
from config.sequencer import SequencerDevConfig
Expand All @@ -16,14 +16,6 @@ def get_pvc() -> objects.PersistentVolumeClaim:
)


def get_port_mappings() -> typing.Sequence[objects.PortMapping]:
return [
objects.PortMapping(name="http", port=80, container_port=8080),
objects.PortMapping(name="rpc", port=8081, container_port=8081),
objects.PortMapping(name="monitoring", port=8082, container_port=8082)
]


def get_config() -> objects.Config:
return SequencerDevConfig(
mount_path="/config/sequencer/presets/",
Expand All @@ -49,7 +41,7 @@ def get_ingress() -> objects.Ingress:
path="/monitoring/",
path_type="Prefix",
backend_service_name="sequencer-node-service",
backend_service_port_number=8082
backend_service_port_number=const.MONITORING_SERVICE_PORT
)
]
)
Expand All @@ -67,23 +59,23 @@ def get_ingress() -> objects.Ingress:

def get_service() -> objects.Service:
return objects.Service(
type=objects.ServiceType.CLUSTER_IP.value,
type=const.CLUSTER_IP,
selector={},
ports=[
objects.PortMapping(
name="http",
port=80,
container_port=8080
port=const.HTTP_SERVICE_PORT,
container_port=const.HTTP_CONTAINER_PORT
),
objects.PortMapping(
name="rpc",
port=8081,
container_port=8081
port=const.RPC_SERVICE_PORT,
container_port=const.RPC_CONTAINER_PORT
),
objects.PortMapping(
name="monitoring",
port=8082,
container_port=8082
port=const.MONITORING_SERVICE_PORT,
container_port=const.MONITORING_CONTAINER_PORT
)
]
)
Expand All @@ -99,13 +91,13 @@ def get_deployment() -> objects.Deployment:
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.3",
args=["--config_file", "/config/sequencer/presets/config"],
ports=[
objects.ContainerPort(container_port=8080),
objects.ContainerPort(container_port=8081),
objects.ContainerPort(container_port=8082)
objects.ContainerPort(container_port=const.HTTP_CONTAINER_PORT),
objects.ContainerPort(container_port=const.RPC_CONTAINER_PORT),
objects.ContainerPort(container_port=const.MONITORING_CONTAINER_PORT)
],
startup_probe=objects.Probe(port=8082, path="/monitoring/nodeVersion", period_seconds=10, failure_threshold=10, timeout_seconds=5),
readiness_probe=objects.Probe(port=8082, path="/monitoring/ready", period_seconds=10, failure_threshold=5, timeout_seconds=5),
liveness_probe=objects.Probe(port=8082, path="/monitoring/alive", period_seconds=10, failure_threshold=5, timeout_seconds=5),
startup_probe=objects.Probe(port=const.MONITORING_CONTAINER_PORT, path="/monitoring/nodeVersion", period_seconds=10, failure_threshold=10, timeout_seconds=5),
readiness_probe=objects.Probe(port=const.MONITORING_CONTAINER_PORT, path="/monitoring/ready", period_seconds=10, failure_threshold=5, timeout_seconds=5),
liveness_probe=objects.Probe(port=const.MONITORING_CONTAINER_PORT, path="/monitoring/alive", period_seconds=10, failure_threshold=5, timeout_seconds=5),
volume_mounts=[
objects.VolumeMount(
name="config",
Expand Down

0 comments on commit 0bfc1fe

Please sign in to comment.