@@ -9,7 +9,7 @@ kind_cmd = "./hack/tools/bin/kind"
99os .putenv ("PATH" , os .getenv ("PATH" ) + ":" + tools_bin )
1010
1111update_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"]
3131settings .update (
3232 read_json (
3333 "tilt-settings.json" ,
34- default = {},
35- )
34+ default = {},
35+ ),
3636)
3737
3838if settings .get ("trigger_mode" ) == "manual" :
@@ -44,25 +44,28 @@ if "allowed_contexts" in settings:
4444if "default_registry" in settings :
4545 default_registry (settings .get ("default_registry" ))
4646
47-
4847# deploy CAPI
4948def 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-
7779def 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.
105111def include_user_tilt_files ():
106112 user_tiltfiles = listdir ("tilt.d" )
107113 for f in user_tiltfiles :
108114 include (f )
109115
110-
111116def 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-
126133def 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-
131137def 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-
142147tilt_helper_dockerfile_header = """
143148# Tilt image
144149FROM golang:1.23.6 as tilt-helper
@@ -161,15 +166,14 @@ COPY --from=tilt-helper /go/bin/dlv .
161166COPY manager .
162167"""
163168
164-
165169# Build CAPG and add feature gates
166170def capg ():
167171 # Apply the kustomized yaml for this provider
168172 substitutions = settings .get ("kustomize_substitutions" , {})
169173 os .environ .update (substitutions )
170174
171175 yaml = str (
172- kustomizesub ("./hack/observability" )
176+ kustomizesub ("./hack/observability" ),
173177 ) # build an observable kind deployment by default
174178 # TODO: consider to remove
175179 # yaml = str(kustomizesub("./config/default"))
@@ -192,8 +196,8 @@ def capg():
192196 # Set up a local_resource build of the provider's manager binary.
193197 local_resource (
194198 "manager" ,
195- cmd = "mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \" -static\" ' -o .tiltbuild/manager" ,
196- deps = [
199+ cmd = "mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \" -static\" ' -o .tiltbuild/manager" ,
200+ deps = [
197201 "api" ,
198202 "cloud" ,
199203 "config" ,
@@ -211,7 +215,7 @@ def capg():
211215 [
212216 tilt_helper_dockerfile_header ,
213217 tilt_dockerfile_header ,
214- ]
218+ ],
215219 )
216220
217221 entrypoint = ["sh" , "/start.sh" , "/manager" ]
@@ -222,111 +226,105 @@ def capg():
222226 # Set up an image build for the provider. The live update configuration syncs the output from the local_resource
223227 # build into the container.
224228 docker_build (
225- ref = "gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller" ,
226- context = "./.tiltbuild/" ,
227- dockerfile_contents = dockerfile_contents ,
228- target = "tilt" ,
229- entrypoint = entrypoint ,
230- only = "manager" ,
231- live_update = [
229+ ref = "gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller" ,
230+ context = "./.tiltbuild/" ,
231+ dockerfile_contents = dockerfile_contents ,
232+ target = "tilt" ,
233+ entrypoint = entrypoint ,
234+ only = "manager" ,
235+ live_update = [
232236 sync (".tiltbuild/manager" , "/manager" ),
233237 run ("sh /restart.sh" ),
234238 ],
235- ignore = ["templates" ],
239+ ignore = ["templates" ],
236240 )
237241
238242 k8s_yaml (blob (yaml ))
239243
240-
241244def observability ():
242245 # Install the OpenTelemetry helm chart
243246 gcp_project_id = os .getenv ("GCP_PROJECT_ID" , "" )
244247
245248 k8s_yaml (
246249 helm (
247250 "./hack/observability/opentelemetry/chart" ,
248- name = "opentelemetry-collector" ,
249- namespace = "capg-system" ,
250- values = ["./hack/observability/opentelemetry/values.yaml" ],
251+ name = "opentelemetry-collector" ,
252+ namespace = "capg-system" ,
253+ values = ["./hack/observability/opentelemetry/values.yaml" ],
251254 # refer https://github.com/helm/helm/issues/1987
252- set = [
255+ set = [
253256 "extraEnvs[0].name=GCP_PROJECT_ID" ,
254257 "extraEnvs[0].value=" + gcp_project_id ,
255258 ],
256- )
259+ ),
257260 )
258261
259262 k8s_yaml (
260263 helm (
261264 "./hack/observability/jaeger/chart" ,
262- name = "jaeger-all-in-one" ,
263- namespace = "capg-system" ,
264- set = [
265+ name = "jaeger-all-in-one" ,
266+ namespace = "capg-system" ,
267+ set = [
265268 # TODO: consider to remove
266269 # "crd.install=false",
267270 # "rbac.create=false",
268271 "resources.limits.cpu=200m" ,
269272 "resources.limits.memory=256Mi" ,
270273 ],
271- )
274+ ),
272275 )
273276
274277 k8s_resource (
275- workload = "jaeger-all-in-one" ,
276- new_name = "traces: jaeger-all-in-one" ,
277- port_forwards = [
278- port_forward (16686 , name = "View traces" , link_path = "/search?service=capg" )
278+ workload = "jaeger-all-in-one" ,
279+ new_name = "traces: jaeger-all-in-one" ,
280+ port_forwards = [
281+ port_forward (16686 , name = "View traces" , link_path = "/search?service=capg" ),
279282 ],
280- labels = ["observability" ],
283+ labels = ["observability" ],
281284 )
282285
283- k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
284-
286+ k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
285287
286288def base64_encode (to_encode ):
287289 encode_blob = local (
288- "echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ), quiet = True
290+ "echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ),
291+ quiet = True ,
289292 )
290293 return str (encode_blob )
291294
292-
293295def base64_encode_file (path_to_encode ):
294296 encode_blob = local (
295- "cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ), quiet = True
297+ "cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ),
298+ quiet = True ,
296299 )
297300 return str (encode_blob )
298301
299-
300302def read_file_from_path (path_to_read ):
301- str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
303+ str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
302304 return str (str_blob )
303305
304-
305306def base64_decode (to_decode ):
306- decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
307+ decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
307308 return str (decode_blob )
308309
309-
310310def kustomizesub (folder ):
311- yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
311+ yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
312312 return yaml
313313
314-
315314def waitforsystem ():
316315 local (
317- kubectl_cmd
318- + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system"
316+ kubectl_cmd +
317+ " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system" ,
319318 )
320319 local (
321- kubectl_cmd
322- + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system"
320+ kubectl_cmd +
321+ " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system" ,
323322 )
324323 local (
325- kubectl_cmd
326- + " wait --for=condition=ready --timeout=300s pod --all -n capi-system"
324+ kubectl_cmd +
325+ " wait --for=condition=ready --timeout=300s pod --all -n capi-system" ,
327326 )
328327
329-
330328##############################
331329# Actual work happens here
332330##############################
0 commit comments