diff --git a/stack_orchestrator/deploy/deployer.py b/stack_orchestrator/deploy/deployer.py index 1da7bd38..57e45f34 100644 --- a/stack_orchestrator/deploy/deployer.py +++ b/stack_orchestrator/deploy/deployer.py @@ -70,13 +70,11 @@ class Deployer(ABC): pass def prepare(self, skip_cluster_management): - """Create cluster infrastructure (namespace, PVs, services) without starting pods. + """Create cluster infra (namespace, PVs, services) without pods. Only supported for k8s deployers. Compose deployers raise an error. """ - raise DeployerException( - "prepare is only supported for k8s deployments" - ) + raise DeployerException("prepare is only supported for k8s deployments") class DeployerException(Exception): diff --git a/stack_orchestrator/deploy/k8s/cluster_info.py b/stack_orchestrator/deploy/k8s/cluster_info.py index 71cbd9f5..36df515d 100644 --- a/stack_orchestrator/deploy/k8s/cluster_info.py +++ b/stack_orchestrator/deploy/k8s/cluster_info.py @@ -208,6 +208,7 @@ class ClusterInfo: certificate = (certificates or {}).get(host_name) if use_tls: + assert tls is not None tls.append( client.V1IngressTLS( hosts=( @@ -835,9 +836,12 @@ class ClusterInfo: containers, init_containers, services, volumes = self._build_containers( single_pod_map, image_pull_policy ) - annotations, labels, affinity, tolerations = ( - self._build_common_pod_metadata(services) - ) + ( + annotations, + labels, + affinity, + tolerations, + ) = self._build_common_pod_metadata(services) # Add pod-name label so Services can target specific pods if multi_pod: @@ -860,9 +864,12 @@ class ClusterInfo: selector_labels["app.kubernetes.io/component"] = pod_name # Add CA certificate volume and env vars if configured - _ca_secret, ca_volume, ca_mounts, ca_envs = ( - self.get_ca_certificate_resources() - ) + ( + _ca_secret, + ca_volume, + ca_mounts, + ca_envs, + ) = self.get_ca_certificate_resources() if ca_volume: volumes.append(ca_volume) for container in containers: @@ -1112,9 +1119,7 @@ class ClusterInfo: spec=client.V1ServiceSpec( type="ExternalName", external_name=config["host"], - ports=[ - client.V1ServicePort(port=port, name=f"port-{port}") - ], + ports=[client.V1ServicePort(port=port, name=f"port-{port}")], ), ) resources.append(svc) @@ -1130,9 +1135,7 @@ class ClusterInfo: ), spec=client.V1ServiceSpec( cluster_ip="None", - ports=[ - client.V1ServicePort(port=port, name=f"port-{port}") - ], + ports=[client.V1ServicePort(port=port, name=f"port-{port}")], ), ) resources.append(svc) diff --git a/stack_orchestrator/deploy/k8s/deploy_k8s.py b/stack_orchestrator/deploy/k8s/deploy_k8s.py index 3afff76d..0b2dd7ae 100644 --- a/stack_orchestrator/deploy/k8s/deploy_k8s.py +++ b/stack_orchestrator/deploy/k8s/deploy_k8s.py @@ -439,7 +439,9 @@ class K8sDeployer(Deployer): for resource in resources: if opts.o.dry_run: - print(f"Dry run: would create external service: {resource.metadata.name}") + print( + f"Dry run: would create external service: {resource.metadata.name}" + ) continue svc_name = resource.metadata.name @@ -478,9 +480,7 @@ class K8sDeployer(Deployer): namespace=target_ns, label_selector=label_selector ) pod_ips = [ - p.status.pod_ip - for p in pods.items - if p.status and p.status.pod_ip + p.status.pod_ip for p in pods.items if p.status and p.status.pod_ip ] if not pod_ips: @@ -497,13 +497,9 @@ class K8sDeployer(Deployer): ), subsets=[ client.V1EndpointSubset( - addresses=[ - client.V1EndpointAddress(ip=ip) for ip in pod_ips - ], + addresses=[client.V1EndpointAddress(ip=ip) for ip in pod_ips], ports=[ - client.CoreV1EndpointPort( - port=port, name=f"port-{port}" - ) + client.CoreV1EndpointPort(port=port, name=f"port-{port}") ], ) ], diff --git a/stack_orchestrator/ids.py b/stack_orchestrator/ids.py index 97e7cb11..c773b026 100644 --- a/stack_orchestrator/ids.py +++ b/stack_orchestrator/ids.py @@ -37,7 +37,7 @@ def _random_suffix(length: int = 2) -> str: def _timestamp_id() -> str: - """Generate a sortable timestamp ID (100ms resolution, 2024 epoch) with random suffix.""" + """Generate sortable timestamp ID with random suffix.""" now_ms = int(time.time() * 1000) offset = (now_ms - EPOCH_2024) // 100 # 100ms resolution return f"{_base36(offset)}{_random_suffix()}"