@@ -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.18 as tilt-helper
@@ -156,15 +161,14 @@ COPY --from=tilt-helper /restart.sh .
156
161
COPY manager .
157
162
"""
158
163
159
-
160
164
# Build CAPG and add feature gates
161
165
def capg ():
162
166
# Apply the kustomized yaml for this provider
163
167
substitutions = settings .get ("kustomize_substitutions" , {})
164
168
os .environ .update (substitutions )
165
169
166
170
yaml = str (
167
- kustomizesub ("./hack/observability" )
171
+ kustomizesub ("./hack/observability" ),
168
172
) # build an observable kind deployment by default
169
173
# TODO: consider to remove
170
174
# yaml = str(kustomizesub("./config/default"))
@@ -187,8 +191,8 @@ def capg():
187
191
# Set up a local_resource build of the provider's manager binary.
188
192
local_resource (
189
193
"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 = [
192
196
"api" ,
193
197
"cloud" ,
194
198
"config" ,
@@ -206,7 +210,7 @@ def capg():
206
210
[
207
211
tilt_helper_dockerfile_header ,
208
212
tilt_dockerfile_header ,
209
- ]
213
+ ],
210
214
)
211
215
212
216
entrypoint = ["sh" , "/start.sh" , "/manager" ]
@@ -217,111 +221,105 @@ def capg():
217
221
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
218
222
# build into the container.
219
223
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 = [
227
231
sync (".tiltbuild/manager" , "/manager" ),
228
232
run ("sh /restart.sh" ),
229
233
],
230
- ignore = ["templates" ],
234
+ ignore = ["templates" ],
231
235
)
232
236
233
237
k8s_yaml (blob (yaml ))
234
238
235
-
236
239
def observability ():
237
240
# Install the OpenTelemetry helm chart
238
241
gcp_project_id = os .getenv ("GCP_PROJECT_ID" , "" )
239
242
240
243
k8s_yaml (
241
244
helm (
242
245
"./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" ],
246
249
# refer https://github.com/helm/helm/issues/1987
247
- set = [
250
+ set = [
248
251
"extraEnvs[0].name=GCP_PROJECT_ID" ,
249
252
"extraEnvs[0].value=" + gcp_project_id ,
250
253
],
251
- )
254
+ ),
252
255
)
253
256
254
257
k8s_yaml (
255
258
helm (
256
259
"./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 = [
260
263
# TODO: consider to remove
261
264
# "crd.install=false",
262
265
# "rbac.create=false",
263
266
"resources.limits.cpu=200m" ,
264
267
"resources.limits.memory=256Mi" ,
265
268
],
266
- )
269
+ ),
267
270
)
268
271
269
272
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" ),
274
277
],
275
- labels = ["observability" ],
278
+ labels = ["observability" ],
276
279
)
277
280
278
- k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
279
-
281
+ k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
280
282
281
283
def base64_encode (to_encode ):
282
284
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 ,
284
287
)
285
288
return str (encode_blob )
286
289
287
-
288
290
def base64_encode_file (path_to_encode ):
289
291
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 ,
291
294
)
292
295
return str (encode_blob )
293
296
294
-
295
297
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 )
297
299
return str (str_blob )
298
300
299
-
300
301
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 )
302
303
return str (decode_blob )
303
304
304
-
305
305
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 )
307
307
return yaml
308
308
309
-
310
309
def waitforsystem ():
311
310
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" ,
314
313
)
315
314
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" ,
318
317
)
319
318
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" ,
322
321
)
323
322
324
-
325
323
##############################
326
324
# Actual work happens here
327
325
##############################
0 commit comments