Skip to content

Commit

Permalink
chore: enhanced defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-starkware committed Nov 17, 2024
1 parent ccae39a commit cfabecb
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 112 deletions.
2 changes: 1 addition & 1 deletion deployments/sequencer/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 5 additions & 5 deletions deployments/sequencer/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 44 additions & 94 deletions deployments/sequencer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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()
81 changes: 76 additions & 5 deletions deployments/sequencer/services/defaults.py
Original file line number Diff line number Diff line change
@@ -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"
)
]
)
)


12 changes: 6 additions & 6 deletions deployments/sequencer/services/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +42,7 @@ class PersistentVolumeClaim:


@dataclasses.dataclass
class Config():
class Config:
schema: Dict[Any, Any]
config: Dict[Any, Any]
mount_path: str
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deployments/sequencer/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cfabecb

Please sign in to comment.