Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit ee8518d

Browse files
authored
dev: support executing kubernetes dev setup on command execution (#13509)
1 parent d6882f9 commit ee8518d

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

localstack-core/localstack/dev/kubernetes/__main__.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import dataclasses
22
import os
3+
import shlex
4+
import subprocess as sp
35
from typing import Literal
46

57
import click
@@ -315,12 +317,11 @@ def generate_k8s_helm_overrides(
315317
return overrides
316318

317319

318-
def write_file(content: dict, output_path: str, file_name: str):
319-
path = os.path.join(output_path, file_name)
320-
with open(path, "w") as f:
320+
def write_file(content: dict, output_path: str):
321+
with open(output_path, "w") as f:
321322
f.write(yaml.dump(content))
322323
f.close()
323-
print(f"Generated file at {path}")
324+
print(f"Generated file at {output_path}")
324325

325326

326327
def print_file(content: dict, file_name: str):
@@ -330,6 +331,22 @@ def print_file(content: dict, file_name: str):
330331
print("=====================================")
331332

332333

334+
def generate_k3d_command(config_file_path: str) -> str:
335+
return f"k3d cluster create --config {config_file_path}"
336+
337+
338+
def generate_helm_command(overrides_file_path: str) -> str:
339+
return f"helm upgrade --install localstack localstack/localstack -f {overrides_file_path}"
340+
341+
342+
def execute_deployment(config_file_path: str, overrides_file_path: str):
343+
"""
344+
Use the k3d and helm commands to create a cluster and deploy LocalStack in one command
345+
"""
346+
sp.check_call(shlex.split(generate_k3d_command(config_file_path)))
347+
sp.check_call(shlex.split(generate_helm_command(overrides_file_path)))
348+
349+
333350
@click.command("run")
334351
@click.option(
335352
"--pro", is_flag=True, default=None, help="Mount the localstack-pro code into the cluster."
@@ -386,6 +403,13 @@ def print_file(content: dict, file_name: str):
386403
help="DNS port to expose from the kubernetes node. It is applied only if --expose-dns is set.",
387404
type=click.IntRange(0, 65535),
388405
)
406+
@click.option(
407+
"--execute",
408+
"-x",
409+
is_flag=True,
410+
default=False,
411+
help="Execute deployment from generated config files. Implies -w/--write.",
412+
)
389413
@click.argument("command", nargs=-1, required=False)
390414
def run(
391415
pro: bool = None,
@@ -400,6 +424,7 @@ def run(
400424
port: int = None,
401425
expose_dns: bool = False,
402426
dns_port: int = 53,
427+
execute: bool = False,
403428
):
404429
"""
405430
A tool for localstack developers to generate the kubernetes cluster configuration file and the overrides to mount the localstack code into the cluster.
@@ -416,25 +441,25 @@ def run(
416441
overrides_file = overrides_file or "overrides.yml"
417442
config_file = config_file or "configuration.yml"
418443

419-
if write:
420-
write_file(config, output_dir, config_file)
421-
write_file(overrides, output_dir, overrides_file)
444+
overrides_file_path = os.path.join(output_dir, overrides_file)
445+
config_file_path = os.path.join(output_dir, config_file)
446+
447+
if write or execute:
448+
write_file(config, config_file_path)
449+
write_file(overrides, overrides_file_path)
450+
if execute:
451+
execute_deployment(config_file, overrides_file)
422452
else:
423453
print_file(config, config_file)
424454
print_file(overrides, overrides_file)
425455

426-
overrides_file_path = os.path.join(output_dir, overrides_file)
427-
config_file_path = os.path.join(output_dir, config_file)
428-
429456
print("\nTo create a k3d cluster with the generated configuration, follow these steps:")
430457
print("1. Run the following command to create the cluster:")
431-
print(f"\n k3d cluster create --config {config_file_path}\n")
458+
print(f"\n {generate_k3d_command(config_file_path)}\n")
432459

433460
print("2. Once the cluster is created, start LocalStack with the generated overrides:")
434461
print("\n helm repo add localstack https://localstack.github.io/helm-charts # (if required)")
435-
print(
436-
f"\n helm upgrade --install localstack localstack/localstack -f {overrides_file_path}\n"
437-
)
462+
print(f"\n {generate_helm_command(overrides_file_path)}\n")
438463

439464

440465
def main():

0 commit comments

Comments
 (0)