diff --git a/deployments/sequencer/app/service.py b/deployments/sequencer/app/service.py index 3dce732edb..32d19d09a6 100644 --- a/deployments/sequencer/app/service.py +++ b/deployments/sequencer/app/service.py @@ -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: diff --git a/deployments/sequencer/services/const.py b/deployments/sequencer/services/const.py new file mode 100644 index 0000000000..f3d1b26b76 --- /dev/null +++ b/deployments/sequencer/services/const.py @@ -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 diff --git a/deployments/sequencer/services/objects.py b/deployments/sequencer/services/objects.py index 0fc5fe2e13..0746319403 100644 --- a/deployments/sequencer/services/objects.py +++ b/deployments/sequencer/services/objects.py @@ -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 @@ -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] @@ -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 diff --git a/deployments/sequencer/services/topology.py b/deployments/sequencer/services/topology.py index 9092d6ed21..be9ebaa7c8 100644 --- a/deployments/sequencer/services/topology.py +++ b/deployments/sequencer/services/topology.py @@ -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) diff --git a/deployments/sequencer/services/topology_helpers.py b/deployments/sequencer/services/topology_helpers.py index 3e1b1a5db3..9d425ec254 100644 --- a/deployments/sequencer/services/topology_helpers.py +++ b/deployments/sequencer/services/topology_helpers.py @@ -1,4 +1,4 @@ -import typing +import const from services import objects from config.sequencer import SequencerDevConfig @@ -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/", @@ -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 ) ] ) @@ -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 ) ] ) @@ -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",