Skip to content

Commit bbc5bf5

Browse files
committed
reformat tilt file
1 parent 085b48f commit bbc5bf5

File tree

1 file changed

+72
-74
lines changed

1 file changed

+72
-74
lines changed

Tiltfile

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kind_cmd = "./hack/tools/bin/kind"
99
os.putenv("PATH", os.getenv("PATH") + ":" + tools_bin)
1010

1111
update_settings(
12-
k8s_upsert_timeout_secs=60
12+
k8s_upsert_timeout_secs = 60,
1313
) # on first tilt up, often can take longer than 30 seconds
1414

1515
# set defaults
@@ -31,8 +31,8 @@ keys = ["GCP_B64ENCODED_CREDENTIALS"]
3131
settings.update(
3232
read_json(
3333
"tilt-settings.json",
34-
default={},
35-
)
34+
default = {},
35+
),
3636
)
3737

3838
if settings.get("trigger_mode") == "manual":
@@ -44,25 +44,28 @@ if "allowed_contexts" in settings:
4444
if "default_registry" in settings:
4545
default_registry(settings.get("default_registry"))
4646

47-
4847
# deploy CAPI
4948
def deploy_capi():
5049
version = settings.get("capi_version")
5150
capi_uri = "https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml".format(
52-
version
51+
version,
5352
)
5453
cmd = "curl -sSL {} | {} | {} apply -f -".format(
55-
capi_uri, envsubst_cmd, kubectl_cmd
54+
capi_uri,
55+
envsubst_cmd,
56+
kubectl_cmd,
5657
)
57-
local(cmd, quiet=True)
58+
local(cmd, quiet = True)
5859
if settings.get("extra_args"):
5960
extra_args = settings.get("extra_args")
6061
if extra_args.get("core"):
6162
core_extra_args = extra_args.get("core")
6263
if core_extra_args:
6364
for namespace in ["capi-system"]:
6465
patch_args_with_extra_args(
65-
namespace, "capi-controller-manager", core_extra_args
66+
namespace,
67+
"capi-controller-manager",
68+
core_extra_args,
6669
)
6770
if extra_args.get("kubeadm-bootstrap"):
6871
kb_extra_args = extra_args.get("kubeadm-bootstrap")
@@ -73,14 +76,15 @@ def deploy_capi():
7376
kb_extra_args,
7477
)
7578

76-
7779
def patch_args_with_extra_args(namespace, name, extra_args):
7880
args_str = str(
7981
local(
8082
"{} get deployments {} -n {} -o jsonpath={{.spec.template.spec.containers[0].args}}".format(
81-
kubectl_cmd, name, namespace
82-
)
83-
)
83+
kubectl_cmd,
84+
name,
85+
namespace,
86+
),
87+
),
8488
)
8589
args_to_add = [arg for arg in extra_args if arg not in args_str]
8690
if args_to_add:
@@ -91,54 +95,55 @@ def patch_args_with_extra_args(namespace, name, extra_args):
9195
"op": "replace",
9296
"path": "/spec/template/spec/containers/0/args",
9397
"value": args,
94-
}
98+
},
9599
]
96100
local(
97101
"{} patch deployment {} -n {} --type json -p='{}'".format(
98-
kubectl_cmd, name, namespace, str(encode_json(patch)).replace("\n", "")
99-
)
102+
kubectl_cmd,
103+
name,
104+
namespace,
105+
str(encode_json(patch)).replace("\n", ""),
106+
),
100107
)
101108

102-
103109
# Users may define their own Tilt customizations in tilt.d. This directory is excluded from git and these files will
104110
# not be checked in to version control.
105111
def include_user_tilt_files():
106112
user_tiltfiles = listdir("tilt.d")
107113
for f in user_tiltfiles:
108114
include(f)
109115

110-
111116
def append_arg_for_container_in_deployment(
112-
yaml_stream, name, namespace, contains_image_name, args
113-
):
117+
yaml_stream,
118+
name,
119+
namespace,
120+
contains_image_name,
121+
args):
114122
for item in yaml_stream:
115123
if (
116-
item["kind"] == "Deployment"
117-
and item.get("metadata").get("name") == name
118-
and item.get("metadata").get("namespace") == namespace
124+
item["kind"] == "Deployment" and
125+
item.get("metadata").get("name") == name and
126+
item.get("metadata").get("namespace") == namespace
119127
):
120128
containers = item.get("spec").get("template").get("spec").get("containers")
121129
for container in containers:
122130
if contains_image_name in container.get("image"):
123131
container.get("args").extend(args)
124132

125-
126133
def fixup_yaml_empty_arrays(yaml_str):
127134
yaml_str = yaml_str.replace("conditions: null", "conditions: []")
128135
return yaml_str.replace("storedVersions: null", "storedVersions: []")
129136

130-
131137
def validate_auth():
132138
substitutions = settings.get("kustomize_substitutions", {})
133139
missing = [k for k in keys if k not in substitutions]
134140
if missing:
135141
fail(
136142
"missing kustomize_substitutions keys {} in tilt-settings.json".format(
137-
missing
138-
)
143+
missing,
144+
),
139145
)
140146

141-
142147
tilt_helper_dockerfile_header = """
143148
# Tilt image
144149
FROM golang:1.18 as tilt-helper
@@ -156,15 +161,14 @@ COPY --from=tilt-helper /restart.sh .
156161
COPY manager .
157162
"""
158163

159-
160164
# Build CAPG and add feature gates
161165
def capg():
162166
# Apply the kustomized yaml for this provider
163167
substitutions = settings.get("kustomize_substitutions", {})
164168
os.environ.update(substitutions)
165169

166170
yaml = str(
167-
kustomizesub("./hack/observability")
171+
kustomizesub("./hack/observability"),
168172
) # build an observable kind deployment by default
169173
# TODO: consider to remove
170174
# yaml = str(kustomizesub("./config/default"))
@@ -187,8 +191,8 @@ def capg():
187191
# Set up a local_resource build of the provider's manager binary.
188192
local_resource(
189193
"manager",
190-
cmd="mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \"-static\"' -o .tiltbuild/manager",
191-
deps=[
194+
cmd = "mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \"-static\"' -o .tiltbuild/manager",
195+
deps = [
192196
"api",
193197
"cloud",
194198
"config",
@@ -206,7 +210,7 @@ def capg():
206210
[
207211
tilt_helper_dockerfile_header,
208212
tilt_dockerfile_header,
209-
]
213+
],
210214
)
211215

212216
entrypoint = ["sh", "/start.sh", "/manager"]
@@ -217,111 +221,105 @@ def capg():
217221
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
218222
# build into the container.
219223
docker_build(
220-
ref="gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller",
221-
context="./.tiltbuild/",
222-
dockerfile_contents=dockerfile_contents,
223-
target="tilt",
224-
entrypoint=entrypoint,
225-
only="manager",
226-
live_update=[
224+
ref = "gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller",
225+
context = "./.tiltbuild/",
226+
dockerfile_contents = dockerfile_contents,
227+
target = "tilt",
228+
entrypoint = entrypoint,
229+
only = "manager",
230+
live_update = [
227231
sync(".tiltbuild/manager", "/manager"),
228232
run("sh /restart.sh"),
229233
],
230-
ignore=["templates"],
234+
ignore = ["templates"],
231235
)
232236

233237
k8s_yaml(blob(yaml))
234238

235-
236239
def observability():
237240
# Install the OpenTelemetry helm chart
238241
gcp_project_id = os.getenv("GCP_PROJECT_ID", "")
239242

240243
k8s_yaml(
241244
helm(
242245
"./hack/observability/opentelemetry/chart",
243-
name="opentelemetry-collector",
244-
namespace="capg-system",
245-
values=["./hack/observability/opentelemetry/values.yaml"],
246+
name = "opentelemetry-collector",
247+
namespace = "capg-system",
248+
values = ["./hack/observability/opentelemetry/values.yaml"],
246249
# refer https://github.com/helm/helm/issues/1987
247-
set=[
250+
set = [
248251
"extraEnvs[0].name=GCP_PROJECT_ID",
249252
"extraEnvs[0].value=" + gcp_project_id,
250253
],
251-
)
254+
),
252255
)
253256

254257
k8s_yaml(
255258
helm(
256259
"./hack/observability/jaeger/chart",
257-
name="jaeger-all-in-one",
258-
namespace="capg-system",
259-
set=[
260+
name = "jaeger-all-in-one",
261+
namespace = "capg-system",
262+
set = [
260263
# TODO: consider to remove
261264
# "crd.install=false",
262265
# "rbac.create=false",
263266
"resources.limits.cpu=200m",
264267
"resources.limits.memory=256Mi",
265268
],
266-
)
269+
),
267270
)
268271

269272
k8s_resource(
270-
workload="jaeger-all-in-one",
271-
new_name="traces: jaeger-all-in-one",
272-
port_forwards=[
273-
port_forward(16686, name="View traces", link_path="/search?service=capg")
273+
workload = "jaeger-all-in-one",
274+
new_name = "traces: jaeger-all-in-one",
275+
port_forwards = [
276+
port_forward(16686, name = "View traces", link_path = "/search?service=capg"),
274277
],
275-
labels=["observability"],
278+
labels = ["observability"],
276279
)
277280

278-
k8s_resource(workload="opentelemetry-collector", labels=["observability"])
279-
281+
k8s_resource(workload = "opentelemetry-collector", labels = ["observability"])
280282

281283
def base64_encode(to_encode):
282284
encode_blob = local(
283-
"echo '{}' | tr -d '\n' | base64 - | tr -d '\n'".format(to_encode), quiet=True
285+
"echo '{}' | tr -d '\n' | base64 - | tr -d '\n'".format(to_encode),
286+
quiet = True,
284287
)
285288
return str(encode_blob)
286289

287-
288290
def base64_encode_file(path_to_encode):
289291
encode_blob = local(
290-
"cat {} | tr -d '\n' | base64 - | tr -d '\n'".format(path_to_encode), quiet=True
292+
"cat {} | tr -d '\n' | base64 - | tr -d '\n'".format(path_to_encode),
293+
quiet = True,
291294
)
292295
return str(encode_blob)
293296

294-
295297
def read_file_from_path(path_to_read):
296-
str_blob = local("cat {} | tr -d '\n'".format(path_to_read), quiet=True)
298+
str_blob = local("cat {} | tr -d '\n'".format(path_to_read), quiet = True)
297299
return str(str_blob)
298300

299-
300301
def base64_decode(to_decode):
301-
decode_blob = local("echo '{}' | base64 --decode -".format(to_decode), quiet=True)
302+
decode_blob = local("echo '{}' | base64 --decode -".format(to_decode), quiet = True)
302303
return str(decode_blob)
303304

304-
305305
def kustomizesub(folder):
306-
yaml = local("hack/kustomize-sub.sh {}".format(folder), quiet=True)
306+
yaml = local("hack/kustomize-sub.sh {}".format(folder), quiet = True)
307307
return yaml
308308

309-
310309
def waitforsystem():
311310
local(
312-
kubectl_cmd
313-
+ " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system"
311+
kubectl_cmd +
312+
" wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system",
314313
)
315314
local(
316-
kubectl_cmd
317-
+ " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system"
315+
kubectl_cmd +
316+
" wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system",
318317
)
319318
local(
320-
kubectl_cmd
321-
+ " wait --for=condition=ready --timeout=300s pod --all -n capi-system"
319+
kubectl_cmd +
320+
" wait --for=condition=ready --timeout=300s pod --all -n capi-system",
322321
)
323322

324-
325323
##############################
326324
# Actual work happens here
327325
##############################

0 commit comments

Comments
 (0)