Skip to content

Commit d84af40

Browse files
authored
Merge pull request #7574 from chiukapoor/env-in-cmdbutton
✨ Removed the writing of os.environment by passing the 'env' parameter in cmd_button
2 parents 844eff2 + f4c74fe commit d84af40

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Tiltfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "":
1111
load("ext://uibutton", "cmd_button", "location", "text_input")
1212

1313
# set defaults
14-
version_settings(True, ">=0.22.2")
14+
version_settings(True, ">=0.30.8")
1515

1616
settings = {
1717
"enable_providers": ["docker"],
@@ -441,10 +441,6 @@ def cluster_templates():
441441
substitutions["CONTROL_PLANE_MACHINE_COUNT"] = substitutions.get("CONTROL_PLANE_MACHINE_COUNT", "1")
442442
substitutions["WORKER_MACHINE_COUNT"] = substitutions.get("WORKER_MACHINE_COUNT", "3")
443443

444-
# Note: this is a workaround to pass env variables to cmd buttons while this is not supported natively like in local_resource
445-
for name, value in substitutions.items():
446-
os.environ[name] = value
447-
448444
template_dirs = settings.get("template_dirs", {
449445
"docker": ["./test/infrastructure/docker/templates"],
450446
})
@@ -488,6 +484,7 @@ def deploy_clusterclass(clusterclass_name, label, filename, substitutions):
488484
cmd_button(
489485
clusterclass_name + ":apply",
490486
argv = ["bash", "-c", apply_clusterclass_cmd],
487+
env = dictonary_to_list_of_string(substitutions),
491488
resource = clusterclass_name,
492489
icon_name = "note_add",
493490
text = "Apply `" + clusterclass_name + "` ClusterClass",
@@ -499,6 +496,7 @@ def deploy_clusterclass(clusterclass_name, label, filename, substitutions):
499496
cmd_button(
500497
clusterclass_name + ":delete",
501498
argv = ["bash", "-c", delete_clusterclass_cmd],
499+
env = dictonary_to_list_of_string(substitutions),
502500
resource = clusterclass_name,
503501
icon_name = "delete_forever",
504502
text = "Delete `" + clusterclass_name + "` ClusterClass",
@@ -523,6 +521,7 @@ def deploy_cluster_template(template_name, label, filename, substitutions):
523521
cmd_button(
524522
template_name + ":apply",
525523
argv = ["bash", "-c", apply_cluster_template_cmd],
524+
env = dictonary_to_list_of_string(substitutions),
526525
resource = template_name,
527526
icon_name = "add_box",
528527
text = "Create `" + template_name + "` cluster",
@@ -537,6 +536,7 @@ def deploy_cluster_template(template_name, label, filename, substitutions):
537536
cmd_button(
538537
template_name + ":delete",
539538
argv = ["bash", "-c", delete_clusters_cmd],
539+
env = dictonary_to_list_of_string(substitutions),
540540
resource = template_name,
541541
icon_name = "delete_forever",
542542
text = "Delete `" + template_name + "` clusters",
@@ -548,11 +548,19 @@ def deploy_cluster_template(template_name, label, filename, substitutions):
548548
cmd_button(
549549
template_name + ":delete-all",
550550
argv = ["bash", "-c", kubectl_cmd + " delete clusters --all --wait=false"],
551+
env = dictonary_to_list_of_string(substitutions),
551552
resource = template_name,
552553
icon_name = "delete_sweep",
553554
text = "Delete all workload clusters",
554555
)
555556

557+
# A function to convert dictonary to list of strings in a format of "name=value"
558+
def dictonary_to_list_of_string(substitutions):
559+
substitutions_list = []
560+
for name, value in substitutions.items():
561+
substitutions_list.append(name + "=" + value)
562+
return substitutions_list
563+
556564
##############################
557565
# Actual work happens here
558566
##############################

docs/book/src/developer/tilt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ workflow that offers easy deployments and rapid iterative builds.
99

1010
1. [Docker](https://docs.docker.com/install/): v19.03 or newer
1111
1. [kind](https://kind.sigs.k8s.io): v0.17 or newer
12-
1. [Tilt](https://docs.tilt.dev/install.html): v0.22.2 or newer
12+
1. [Tilt](https://docs.tilt.dev/install.html): v0.30.8 or newer
1313
1. [kustomize](https://github.com/kubernetes-sigs/kustomize): provided via `make kustomize`
1414
1. [envsubst](https://github.com/drone/envsubst): provided via `make envsubst`
1515
1. [helm](https://github.com/helm/helm): v3.7.1 or newer

0 commit comments

Comments
 (0)