Skip to content

Commit

Permalink
chore(deployment): cdk8s refactor (starkware-libs#2468)
Browse files Browse the repository at this point in the history
* chore(deployment): get values from sequencer config

* chore(deployment): removed set functions

* chore(deployment): preparation to remove objects.py
  • Loading branch information
idan-starkware authored Dec 29, 2024
1 parent 217d859 commit a5ef0ae
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 233 deletions.
3 changes: 2 additions & 1 deletion config/sequencer/presets/config-batcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"eth_fee_token_address": "0x6",
"strk_fee_token_address": "0x7",
"batcher_config.storage.db_config.path_prefix": "/data",
"batcher_config.storage.db_config.enforce_file_exists": false
"batcher_config.storage.db_config.enforce_file_exists": false,
"validator_id" : "0x1"
}
1 change: 0 additions & 1 deletion deployments/images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# More info on Cargo Chef: https://github.com/LukeMathWalker/cargo-chef

FROM ubuntu:22.04 AS base
# WORKDIR /app

COPY scripts/install_build_tools.sh .
COPY scripts/dependencies.sh .
Expand Down
2 changes: 2 additions & 0 deletions deployments/sequencer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
.idea/
341 changes: 148 additions & 193 deletions deployments/sequencer/app/service.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions deployments/sequencer/config/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class SequencerDevConfig(Config):
def __init__(self, mount_path: str, config_file_path: str = ""):
def __init__(self, config_file_path: str = ""):
super().__init__(
global_config=json.loads(
open(os.path.join(CONFIG_DIR, "default_config.json"), "r").read()
Expand All @@ -19,8 +19,7 @@ def __init__(self, mount_path: str, config_file_path: str = ""):
json.loads(open(os.path.join(CONFIG_DIR, "presets", "config.json"), "r").read())
if not config_file_path
else json.loads(open(os.path.abspath(config_file_path)).read())
),
mount_path=mount_path,
)
)

def validate(self):
Expand Down
Binary file not shown.
Binary file modified deployments/sequencer/imports/k8s/_jsii/[email protected]
Binary file not shown.
6 changes: 3 additions & 3 deletions deployments/sequencer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def __post_init__(self):

class SequencerNode(Chart):
def __init__(
self, scope: Construct, name: str, namespace: str, topology: topology.ServiceTopology
self, scope: Construct, name: str, namespace: str, service_topology: topology.ServiceTopology
):
super().__init__(scope, name, disable_resource_name_hashes=True, namespace=namespace)
self.service = ServiceApp(self, name, namespace=namespace, topology=topology)
self.service = ServiceApp(self, name, namespace=namespace, service_topology=service_topology)


def main():
Expand All @@ -45,7 +45,7 @@ def main():
scope=app,
name="sequencer-node",
namespace=args.namespace,
topology=system_preset,
service_topology=system_preset,
)

app.synth()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,39 @@ spec:
- args:
- --config_file
- /config/sequencer/presets/config
image: us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.3
image: us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.11
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 5
httpGet:
path: /monitoring/alive
port: 8080
port: 8082
periodSeconds: 10
timeoutSeconds: 5
name: sequencer-node-server
name: sequencer-node
ports:
- containerPort: 8080
- containerPort: 8082
readinessProbe:
failureThreshold: 5
httpGet:
path: /monitoring/ready
port: 8080
path: /monitoring/alive
port: 8082
periodSeconds: 10
timeoutSeconds: 5
startupProbe:
failureThreshold: 10
failureThreshold: 5
httpGet:
path: /monitoring/nodeVersion
port: 8080
path: /monitoring/alive
port: 8082
periodSeconds: 10
timeoutSeconds: 5
volumeMounts:
- mountPath: /config/sequencer/presets/
name: config
name: sequencer-node-config
readOnly: true
- mountPath: /data
name: data
name: sequencer-node-data
readOnly: false
securityContext:
fsGroup: 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Ingress
metadata:
annotations:
acme.cert-manager.io/http01-edit-in-place: "true"
cert-manager.io/common-name: test.gcp-integration.sw-dev.io
cert-manager.io/common-name: sequencer-node.test.sw-dev.io
cert-manager.io/issue-temporary-certificate: "true"
cert-manager.io/issuer: letsencrypt-prod
kubernetes.io/tls-acme: "true"
Expand All @@ -12,18 +12,19 @@ metadata:
name: sequencer-node-ingress
namespace: test
spec:
ingressClassName: premium-rwo
rules:
- host: test.gcp-integration.sw-dev.io
- host: sequencer-node.test.sw-dev.io
http:
paths:
- backend:
service:
name: sequencer-node-service
port:
number: 8082
path: /monitoring/
path: /monitoring
pathType: Prefix
tls:
- hosts:
- test.gcp-integration.sw-dev.io
secretName: sequencer-tls
- sequencer-node.test.sw-dev.io
secretName: sequencer-node-tls
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ metadata:
spec:
ports:
- name: http
port: 80
port: 8080
targetPort: 8080
- name: rpc
port: 8081
targetPort: 8081
- name: monitoring
port: 8082
targetPort: 8082
Expand Down
10 changes: 8 additions & 2 deletions deployments/sequencer/services/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum

# k8s service types
class ServiceType(Enum):
class ServiceType(str, Enum):
CLUSTER_IP = "ClusterIP"
LOAD_BALANCER = "LoadBalancer"
NODE_PORT = "NodePort"
Expand All @@ -14,5 +14,11 @@ class ServiceType(Enum):

# k8s service ports
HTTP_SERVICE_PORT = 80
RPC_SERVICE_PORT = 8081
GRPC_SERVICE_PORT = 8081
MONITORING_SERVICE_PORT = 8082

PROBE_FAILURE_THRESHOLD = 5
PROBE_PERIOD_SECONDS = 10
PROBE_TIMEOUT_SECONDS = 5

CONTAINER_ARGS = ["--config_file", "/config/sequencer/presets/config"]
6 changes: 4 additions & 2 deletions deployments/sequencer/services/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ class PersistentVolumeClaim:
class Config:
global_config: Dict[Any, Any]
config: Dict[Any, Any]
mount_path: str

def _merged_config(self) -> Dict[Any, Any]:
_config = self.global_config.copy()
_config.update(self.config)
return _config

def get_config(self):
def get_merged_config(self):
return self._merged_config()

def get_config(self):
return self.config

def validate(self):
pass

Expand Down
4 changes: 3 additions & 1 deletion deployments/sequencer/services/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

@dataclasses.dataclass
class ServiceTopology:
images: typing.Optional[typing.Mapping] = dataclasses.field(
default_factory=topology_helpers.get_images
)
deployment: typing.Optional[objects.Deployment] = dataclasses.field(
default_factory=topology_helpers.get_deployment
)
Expand All @@ -23,7 +26,6 @@ class ServiceTopology:
default_factory=topology_helpers.get_ingress
)


class SequencerDev(ServiceTopology):
pass

Expand Down
25 changes: 18 additions & 7 deletions deployments/sequencer/services/topology_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from services import objects, const, helpers
import typing

from services import objects, const
from config.sequencer import SequencerDevConfig


cluster_name = "gcp-integration"
replicas = 1

def get_images() -> typing.Dict[str, str]:
return {
"sequencer": "us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.11"
}


def get_pvc() -> objects.PersistentVolumeClaim:
return objects.PersistentVolumeClaim(
access_modes=["ReadWriteOnce"],
Expand All @@ -15,7 +26,7 @@ def get_pvc() -> objects.PersistentVolumeClaim:

def get_dev_config(config_file_path: str) -> objects.Config:
return SequencerDevConfig(
mount_path="/config/sequencer/presets/", config_file_path=config_file_path
config_file_path=config_file_path
)


Expand All @@ -34,7 +45,7 @@ def get_ingress(url: str = "test.gcp-integration.sw-dev.io") -> objects.Ingress:
host=url,
paths=[
objects.IngressRuleHttpPath(
path="/monitoring/",
path="/monitoring",
path_type="Prefix",
backend_service_name="sequencer-node-service",
backend_service_port_number=const.MONITORING_SERVICE_PORT,
Expand All @@ -58,7 +69,7 @@ def get_service() -> objects.Service:
),
objects.PortMapping(
name="rpc",
port=const.RPC_SERVICE_PORT,
port=const.GRPC_SERVICE_PORT,
container_port=const.RPC_CONTAINER_PORT,
),
objects.PortMapping(
Expand All @@ -77,8 +88,8 @@ def get_deployment() -> objects.Deployment:
containers=[
objects.Container(
name="server",
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.3",
args=["--config_file", "/config/sequencer/presets/config"],
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.8",
args=["--config_file", "/app/config/sequencer/presets/config"],
ports=[
objects.ContainerPort(container_port=const.HTTP_CONTAINER_PORT),
objects.ContainerPort(container_port=const.RPC_CONTAINER_PORT),
Expand Down Expand Up @@ -108,7 +119,7 @@ def get_deployment() -> objects.Deployment:
volume_mounts=[
objects.VolumeMount(
name="config",
mount_path="/config/sequencer/presets/",
mount_path="/app/config/sequencer/presets/",
read_only=True,
),
objects.VolumeMount(name="data", mount_path="/data", read_only=False),
Expand Down

0 comments on commit a5ef0ae

Please sign in to comment.