Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee8518d

Browse files
authored
dev: support executing kubernetes dev setup on command execution (#13509)
1 parentd6882f9 commitee8518d

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
importdataclasses
22
importos
3+
importshlex
4+
importsubprocessassp
35
fromtypingimportLiteral
46

57
importclick
@@ -315,12 +317,11 @@ def generate_k8s_helm_overrides(
315317
returnoverrides
316318

317319

318-
defwrite_file(content:dict,output_path:str,file_name:str):
319-
path=os.path.join(output_path,file_name)
320-
withopen(path,"w")asf:
320+
defwrite_file(content:dict,output_path:str):
321+
withopen(output_path,"w")asf:
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
defprint_file(content:dict,file_name:str):
@@ -330,6 +331,22 @@ def print_file(content: dict, file_name: str):
330331
print("=====================================")
331332

332333

334+
defgenerate_k3d_command(config_file_path:str)->str:
335+
returnf"k3d cluster create --config{config_file_path}"
336+
337+
338+
defgenerate_helm_command(overrides_file_path:str)->str:
339+
returnf"helm upgrade --install localstack localstack/localstack -f{overrides_file_path}"
340+
341+
342+
defexecute_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
defrun(
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_fileor"overrides.yml"
417442
config_file=config_fileor"configuration.yml"
418443

419-
ifwrite:
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+
ifwriteorexecute:
448+
write_file(config,config_file_path)
449+
write_file(overrides,overrides_file_path)
450+
ifexecute:
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"\nk3d 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
defmain():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp