From cfabecb8021f27cc6691cbc7941ce1de6c6f718b Mon Sep 17 00:00:00 2001 From: Idan Shamam Date: Sun, 17 Nov 2024 12:15:16 +0200 Subject: [PATCH] chore: enhanced defaults --- deployments/sequencer/Pipfile | 2 +- deployments/sequencer/Pipfile.lock | 10 +- deployments/sequencer/main.py | 138 +++++++-------------- deployments/sequencer/services/defaults.py | 81 +++++++++++- deployments/sequencer/services/objects.py | 12 +- deployments/sequencer/services/service.py | 2 +- 6 files changed, 133 insertions(+), 112 deletions(-) diff --git a/deployments/sequencer/Pipfile b/deployments/sequencer/Pipfile index eaaf631d80..0f2c87ba18 100644 --- a/deployments/sequencer/Pipfile +++ b/deployments/sequencer/Pipfile @@ -6,10 +6,10 @@ verify_ssl = true [dev-packages] [packages] -cdk8s = "~=2.66.2" constructs = "~=10.2.70" jsonschema = "~=4.23.0" mypy = "*" +cdk8s = "*" [requires] python_version = "3.10" diff --git a/deployments/sequencer/Pipfile.lock b/deployments/sequencer/Pipfile.lock index 5053c870f1..929845ea91 100644 --- a/deployments/sequencer/Pipfile.lock +++ b/deployments/sequencer/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "da8d06f161c3a277655af315db0176d4328fb88cd36b308514634f439f3f833b" + "sha256": "4b91fda4ef8bd983ad69375ba1abdb7384516464b63a87c710a6da60f281867f" }, "pipfile-spec": 6, "requires": { @@ -34,12 +34,12 @@ }, "cdk8s": { "hashes": [ - "sha256:bd3bd68cdcd807a6bb91fa541a4b4e201d18198da61e57aceab0e53d661447d2", - "sha256:c09c35cce4af3d1a56afc62f30ce7a058d8f3de967343e44f4d88db5489e89be" + "sha256:ba4d63e78fd29a98dbf2af739087d686d7dc553e37d002d732a7254e03f69935", + "sha256:c1a262e26b2b0b2a2289d987b8cde2ad659e6b9d3a81b176380d8ae4d5259126" ], "index": "pypi", - "markers": "python_version ~= '3.7'", - "version": "==2.66.13" + "markers": "python_version ~= '3.8'", + "version": "==2.69.15" }, "constructs": { "hashes": [ diff --git a/deployments/sequencer/main.py b/deployments/sequencer/main.py index bbc293292d..f0f71d8c51 100644 --- a/deployments/sequencer/main.py +++ b/deployments/sequencer/main.py @@ -28,8 +28,7 @@ def __init__( self, scope: Construct, name: str, - namespace: str, - config: Config, + namespace: str ): super().__init__( scope, name, disable_resource_name_hashes=True, namespace=namespace @@ -38,93 +37,45 @@ def __init__( self, "sequencer-node", image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.1", - args=["--config_file", "/app/config/sequencer/config.json"], - port_mappings=[ - PortMapping(name="http", port=80, container_port=8080), - PortMapping(name="rpc", port=8081, container_port=8081), - PortMapping(name="monitoring", port=8082, container_port=8082) - ], - service_type=ServiceType.CLUSTER_IP, - replicas=1, - config=config, - health_check=HealthCheck( - startup_probe=Probe(port=8082, path="/monitoring/nodeVersion", period_seconds=10, failure_threshold=10, timeout_seconds=5), - readiness_probe=Probe(port=8082, path="/monitoring/ready", period_seconds=10, failure_threshold=5, timeout_seconds=5), - liveness_probe=Probe(port=8082, path="/monitoring/alive", period_seconds=10, failure_threshold=5, timeout_seconds=5) - ), - pvc=PersistentVolumeClaim( - access_modes=["ReadWriteOnce"], - storage_class_name="premium-rwo", - volume_mode="Filesystem", - storage="256Gi", - mount_path="/data", - read_only=False - ), - ingress=Ingress( - None, - "premium-rwo", - rules=[ - IngressRule( - host="sequencer", - paths=[ - IngressRuleHttpPath( - path="/", - path_type="http", - backend_service_name="test", - backend_service_port_name="test", - backend_service_port_number=80, - ), - IngressRuleHttpPath( - path="/rule", - path_type="http", - backend_service_name="test", - backend_service_port_name="test", - backend_service_port_number=80, - ), - ] - ) - ], - tls=[ - IngressTls( - hosts=[ - "test", - "test2" - ], - secret_name="test" - ) - ] - ) + args=defaults.sequencer.args, + port_mappings=defaults.sequencer.port_mappings, + service_type=defaults.sequencer.service_type, + replicas=defaults.sequencer.replicas, + config=defaults.sequencer.config, + health_check=defaults.sequencer.health_check, + pvc=defaults.sequencer.pvc, + ingress=defaults.sequencer.ingress ) -class SequencerSystem(Chart): - def __init__( - self, - scope: Construct, - name: str, - namespace: str, - system_structure: Dict[str, Dict[str, Any]], - ): - super().__init__( - scope, name, disable_resource_name_hashes=True, namespace=namespace - ) - self.mempool = Service( - self, - "mempool", - image="paulbouwer/hello-kubernetes:1.7", - replicas=2, - config=system_structure.config, - health_check=defaults.health_check - ) - self.batcher = Service( - self, - "batcher", - image="ghost", - port_mappings=[ - PortMapping(name="http", port=80, container_port=2368) - ], - health_check=defaults.health_check - ) +# class SequencerSystem(Chart): +# def __init__( +# self, +# scope: Construct, +# name: str, +# namespace: str, +# system_structure: Dict[str, Dict[str, Any]], +# ): +# super().__init__( +# scope, name, disable_resource_name_hashes=True, namespace=namespace +# ) +# self.mempool = Service( +# self, +# "mempool", +# image="paulbouwer/hello-kubernetes:1.7", +# replicas=2, +# config=system_structure.config, +# health_check=defaults.health_check +# ) +# self.batcher = Service( +# self, +# "batcher", +# image="ghost", +# port_mappings=[ +# PortMapping(name="http", port=80, container_port=2368) +# ], +# health_check=defaults.health_check +# ) app = App( @@ -134,15 +85,14 @@ def __init__( sequencer_node = SequencerNode( scope=app, name="sequencer-node", - namespace="sequencer-node-test", - config=None + namespace="sequencer-node-test" ) -a = SequencerSystem( - scope=app, - name="sequencer-system", - namespace="test-namespace", - system_structure=SystemStructure(config=SequencerDevConfig(mount_path="/app/config")), -) +# a = SequencerSystem( +# scope=app, +# name="sequencer-system", +# namespace="test-namespace", +# system_structure=SystemStructure(config=SequencerDevConfig(mount_path="/app/config")), +# ) app.synth() diff --git a/deployments/sequencer/services/defaults.py b/deployments/sequencer/services/defaults.py index 3eb865c338..9349e6a406 100644 --- a/deployments/sequencer/services/defaults.py +++ b/deployments/sequencer/services/defaults.py @@ -1,7 +1,78 @@ -from services.objects import Probe, HealthCheck +import dataclasses -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) +from typing import Sequence, Optional, List +from services.objects import * +from config.sequencer import * + + +@dataclasses.dataclass +class ServiceDefaults: + image: Optional[str] | None = None + replicas: Optional[int] = 1 + service_type: Optional[ServiceType] | None = None + port_mappings: Optional[Sequence[PortMapping]] | None = None + health_check: Optional[HealthCheck] | None = None + pvc: Optional[PersistentVolumeClaim] | None = None + ingress: Optional[Ingress] | None = None + config: Optional[Config] | None = None + args: Optional[List[str]] | None = None + + +sequencer = ServiceDefaults( + replicas=1, + config=SequencerDevConfig(mount_path="/app/config"), + service_type=ServiceType.CLUSTER_IP, + args=["--config_file", "/app/config/sequencer/config.json"], + port_mappings=[ + PortMapping(name="http", port=80, container_port=8080), + PortMapping(name="rpc", port=8081, container_port=8081), + PortMapping(name="monitoring", port=8082, container_port=8082) + ], + health_check=HealthCheck( + startup_probe=Probe(port=8082, path="/monitoring/nodeVersion", period_seconds=10, failure_threshold=10, timeout_seconds=5), + readiness_probe=Probe(port=8082, path="/monitoring/ready", period_seconds=10, failure_threshold=5, timeout_seconds=5), + liveness_probe=Probe(port=8082, path="/monitoring/alive", period_seconds=10, failure_threshold=5, timeout_seconds=5) + ), + pvc=PersistentVolumeClaim( + access_modes=["ReadWriteOnce"], + storage_class_name="premium-rwo", + volume_mode="Filesystem", + storage="256Gi", + mount_path="/data", + read_only=False + ), + ingress=Ingress( + annotations={ + "kubernetes.io/tls-acme": "true", + "cert-manager.io/common-name": "sequencer.gcp-integration.sw-dev.io", + "cert-manager.io/issue-temporary-certificate": "true", + "cert-manager.io/issuer": "letsencrypt-prod", + "acme.cert-manager.io/http01-edit-in-place": "true" + }, + class_name="gce", + rules=[ + IngressRule( + host="sequencer.gcp-integration.sw-dev.io", + paths=[ + IngressRuleHttpPath( + path="/monitoring/", + path_type="Prefix", + backend_service_name="sequencer-node-service", + backend_service_port_name="monitoring", + backend_service_port_number=8082 + ) + ] + ) + ], + tls=[ + IngressTls( + hosts=[ + "sequencer.gcp-integration.sw-dev.io" + ], + secret_name="sequencer-tls" + ) + ] + ) ) + + diff --git a/deployments/sequencer/services/objects.py b/deployments/sequencer/services/objects.py index 6485c1edeb..5db99dcd15 100644 --- a/deployments/sequencer/services/objects.py +++ b/deployments/sequencer/services/objects.py @@ -19,9 +19,9 @@ def __post_init__(self): @dataclasses.dataclass class HealthCheck: - startup_probe: Optional[Probe] = None - readiness_probe: Optional[Probe] = None - liveness_probe: Optional[Probe] = None + startup_probe: Optional[Probe] | None = None + readiness_probe: Optional[Probe] | None = None + liveness_probe: Optional[Probe] | None = None @dataclasses.dataclass @@ -42,7 +42,7 @@ class PersistentVolumeClaim: @dataclasses.dataclass -class Config(): +class Config: schema: Dict[Any, Any] config: Dict[Any, Any] mount_path: str @@ -78,8 +78,8 @@ class IngressRule: @dataclasses.dataclass class IngressTls: - hosts: Sequence[str] | None - secret_name: str | None + hosts: Sequence[str] | None = None + secret_name: str | None = None @dataclasses.dataclass diff --git a/deployments/sequencer/services/service.py b/deployments/sequencer/services/service.py index 5f5a3afeb0..5c8f9d618b 100644 --- a/deployments/sequencer/services/service.py +++ b/deployments/sequencer/services/service.py @@ -171,7 +171,7 @@ def __init__( metadata=k8s.ObjectMeta( name=f"{self.node.id}-ingress", labels=label, - annotations={} + annotations=ingress.annotations ), spec=k8s.IngressSpec( ingress_class_name=ingress.class_name,