From 8769df6c359687c6c1bb7a01ff4ae0065615ec8d Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 9 Mar 2026 09:49:24 +0000 Subject: [PATCH] k8s: add start() hook for post-deployment k8s resource creation Co-Authored-By: Claude Opus 4.6 --- .../deploy/deployment_create.py | 19 +++++++++++++++++++ stack_orchestrator/deploy/k8s/deploy_k8s.py | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/stack_orchestrator/deploy/deployment_create.py b/stack_orchestrator/deploy/deployment_create.py index 21e5ca48..792d8e3d 100644 --- a/stack_orchestrator/deploy/deployment_create.py +++ b/stack_orchestrator/deploy/deployment_create.py @@ -265,6 +265,25 @@ def call_stack_deploy_create(deployment_context, extra_args): imported_stack.create(deployment_context, extra_args) +def call_stack_deploy_start(deployment_context): + """Call start() hooks after k8s deployments and jobs are created. + + The start() hook receives the DeploymentContext, allowing stacks to + create additional k8s resources (Services, etc.) in the deployment namespace. + The namespace can be derived as f"laconic-{deployment_context.id}". + """ + python_file_paths = _commands_plugin_paths(deployment_context.stack.name) + for python_file_path in python_file_paths: + if python_file_path.exists(): + spec = util.spec_from_file_location("commands", python_file_path) + if spec is None or spec.loader is None: + continue + imported_stack = util.module_from_spec(spec) + spec.loader.exec_module(imported_stack) + if _has_method(imported_stack, "start"): + imported_stack.start(deployment_context) + + # Inspect the pod yaml to find config files referenced in subdirectories # other than the one associated with the pod def _find_extra_config_dirs(parsed_pod_file, pod): diff --git a/stack_orchestrator/deploy/k8s/deploy_k8s.py b/stack_orchestrator/deploy/k8s/deploy_k8s.py index 1efdf177..3003129c 100644 --- a/stack_orchestrator/deploy/k8s/deploy_k8s.py +++ b/stack_orchestrator/deploy/k8s/deploy_k8s.py @@ -461,6 +461,11 @@ class K8sDeployer(Deployer): print("NodePort created:") print(f"{nodeport_resp}") + # Call start() hooks — stacks can create additional k8s resources + if self.deployment_context: + from stack_orchestrator.deploy.deployment_create import call_stack_deploy_start + call_stack_deploy_start(self.deployment_context) + def down(self, timeout, volumes, skip_cluster_management): self.skip_cluster_management = skip_cluster_management self.connect_api()