@@ -9,7 +9,7 @@ kind_cmd = "./hack/tools/bin/kind"
9
9
os .putenv ("PATH" , os .getenv ("PATH" ) + ":" + tools_bin )
10
10
11
11
update_settings (
12
- k8s_upsert_timeout_secs = 60
12
+ k8s_upsert_timeout_secs = 60 ,
13
13
) # on first tilt up, often can take longer than 30 seconds
14
14
15
15
# set defaults
@@ -31,8 +31,8 @@ keys = ["GCP_B64ENCODED_CREDENTIALS"]
31
31
settings .update (
32
32
read_json (
33
33
"tilt-settings.json" ,
34
- default = {},
35
- )
34
+ default = {},
35
+ ),
36
36
)
37
37
38
38
if settings .get ("trigger_mode" ) == "manual" :
@@ -44,25 +44,28 @@ if "allowed_contexts" in settings:
44
44
if "default_registry" in settings :
45
45
default_registry (settings .get ("default_registry" ))
46
46
47
-
48
47
# deploy CAPI
49
48
def deploy_capi ():
50
49
version = settings .get ("capi_version" )
51
50
capi_uri = "https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml" .format (
52
- version
51
+ version ,
53
52
)
54
53
cmd = "curl -sSL {} | {} | {} apply -f -" .format (
55
- capi_uri , envsubst_cmd , kubectl_cmd
54
+ capi_uri ,
55
+ envsubst_cmd ,
56
+ kubectl_cmd ,
56
57
)
57
- local (cmd , quiet = True )
58
+ local (cmd , quiet = True )
58
59
if settings .get ("extra_args" ):
59
60
extra_args = settings .get ("extra_args" )
60
61
if extra_args .get ("core" ):
61
62
core_extra_args = extra_args .get ("core" )
62
63
if core_extra_args :
63
64
for namespace in ["capi-system" ]:
64
65
patch_args_with_extra_args (
65
- namespace , "capi-controller-manager" , core_extra_args
66
+ namespace ,
67
+ "capi-controller-manager" ,
68
+ core_extra_args ,
66
69
)
67
70
if extra_args .get ("kubeadm-bootstrap" ):
68
71
kb_extra_args = extra_args .get ("kubeadm-bootstrap" )
@@ -73,14 +76,15 @@ def deploy_capi():
73
76
kb_extra_args ,
74
77
)
75
78
76
-
77
79
def patch_args_with_extra_args (namespace , name , extra_args ):
78
80
args_str = str (
79
81
local (
80
82
"{} 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
+ ),
84
88
)
85
89
args_to_add = [arg for arg in extra_args if arg not in args_str ]
86
90
if args_to_add :
@@ -91,54 +95,55 @@ def patch_args_with_extra_args(namespace, name, extra_args):
91
95
"op" : "replace" ,
92
96
"path" : "/spec/template/spec/containers/0/args" ,
93
97
"value" : args ,
94
- }
98
+ },
95
99
]
96
100
local (
97
101
"{} 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
+ ),
100
107
)
101
108
102
-
103
109
# Users may define their own Tilt customizations in tilt.d. This directory is excluded from git and these files will
104
110
# not be checked in to version control.
105
111
def include_user_tilt_files ():
106
112
user_tiltfiles = listdir ("tilt.d" )
107
113
for f in user_tiltfiles :
108
114
include (f )
109
115
110
-
111
116
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 ):
114
122
for item in yaml_stream :
115
123
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
119
127
):
120
128
containers = item .get ("spec" ).get ("template" ).get ("spec" ).get ("containers" )
121
129
for container in containers :
122
130
if contains_image_name in container .get ("image" ):
123
131
container .get ("args" ).extend (args )
124
132
125
-
126
133
def fixup_yaml_empty_arrays (yaml_str ):
127
134
yaml_str = yaml_str .replace ("conditions: null" , "conditions: []" )
128
135
return yaml_str .replace ("storedVersions: null" , "storedVersions: []" )
129
136
130
-
131
137
def validate_auth ():
132
138
substitutions = settings .get ("kustomize_substitutions" , {})
133
139
missing = [k for k in keys if k not in substitutions ]
134
140
if missing :
135
141
fail (
136
142
"missing kustomize_substitutions keys {} in tilt-settings.json" .format (
137
- missing
138
- )
143
+ missing ,
144
+ ),
139
145
)
140
146
141
-
142
147
tilt_helper_dockerfile_header = """
143
148
# Tilt image
144
149
FROM golang:1.23.6 as tilt-helper
@@ -161,15 +166,14 @@ COPY --from=tilt-helper /go/bin/dlv .
161
166
COPY manager .
162
167
"""
163
168
164
-
165
169
# Build CAPG and add feature gates
166
170
def capg ():
167
171
# Apply the kustomized yaml for this provider
168
172
substitutions = settings .get ("kustomize_substitutions" , {})
169
173
os .environ .update (substitutions )
170
174
171
175
yaml = str (
172
- kustomizesub ("./hack/observability" )
176
+ kustomizesub ("./hack/observability" ),
173
177
) # build an observable kind deployment by default
174
178
# TODO: consider to remove
175
179
# yaml = str(kustomizesub("./config/default"))
@@ -192,8 +196,8 @@ def capg():
192
196
# Set up a local_resource build of the provider's manager binary.
193
197
local_resource (
194
198
"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 = [
197
201
"api" ,
198
202
"cloud" ,
199
203
"config" ,
@@ -211,7 +215,7 @@ def capg():
211
215
[
212
216
tilt_helper_dockerfile_header ,
213
217
tilt_dockerfile_header ,
214
- ]
218
+ ],
215
219
)
216
220
217
221
entrypoint = ["sh" , "/start.sh" , "/manager" ]
@@ -222,111 +226,105 @@ def capg():
222
226
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
223
227
# build into the container.
224
228
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 = [
232
236
sync (".tiltbuild/manager" , "/manager" ),
233
237
run ("sh /restart.sh" ),
234
238
],
235
- ignore = ["templates" ],
239
+ ignore = ["templates" ],
236
240
)
237
241
238
242
k8s_yaml (blob (yaml ))
239
243
240
-
241
244
def observability ():
242
245
# Install the OpenTelemetry helm chart
243
246
gcp_project_id = os .getenv ("GCP_PROJECT_ID" , "" )
244
247
245
248
k8s_yaml (
246
249
helm (
247
250
"./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" ],
251
254
# refer https://github.com/helm/helm/issues/1987
252
- set = [
255
+ set = [
253
256
"extraEnvs[0].name=GCP_PROJECT_ID" ,
254
257
"extraEnvs[0].value=" + gcp_project_id ,
255
258
],
256
- )
259
+ ),
257
260
)
258
261
259
262
k8s_yaml (
260
263
helm (
261
264
"./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 = [
265
268
# TODO: consider to remove
266
269
# "crd.install=false",
267
270
# "rbac.create=false",
268
271
"resources.limits.cpu=200m" ,
269
272
"resources.limits.memory=256Mi" ,
270
273
],
271
- )
274
+ ),
272
275
)
273
276
274
277
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" ),
279
282
],
280
- labels = ["observability" ],
283
+ labels = ["observability" ],
281
284
)
282
285
283
- k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
284
-
286
+ k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
285
287
286
288
def base64_encode (to_encode ):
287
289
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 ,
289
292
)
290
293
return str (encode_blob )
291
294
292
-
293
295
def base64_encode_file (path_to_encode ):
294
296
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 ,
296
299
)
297
300
return str (encode_blob )
298
301
299
-
300
302
def 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 )
302
304
return str (str_blob )
303
305
304
-
305
306
def 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 )
307
308
return str (decode_blob )
308
309
309
-
310
310
def kustomizesub (folder ):
311
- yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
311
+ yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
312
312
return yaml
313
313
314
-
315
314
def waitforsystem ():
316
315
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" ,
319
318
)
320
319
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" ,
323
322
)
324
323
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" ,
327
326
)
328
327
329
-
330
328
##############################
331
329
# Actual work happens here
332
330
##############################
0 commit comments