@@ -5,10 +5,12 @@ tools_bin = "./hack/tools/bin"
5
5
kubectl_cmd = "./hack/tools/bin/kubectl"
6
6
kind_cmd = "./hack/tools/bin/kind"
7
7
8
- #Add tools to path
8
+ # Add tools to path
9
9
os .putenv ("PATH" , os .getenv ("PATH" ) + ":" + tools_bin )
10
10
11
- update_settings (k8s_upsert_timeout_secs = 60 ) # on first tilt up, often can take longer than 30 seconds
11
+ update_settings (
12
+ k8s_upsert_timeout_secs = 60
13
+ ) # on first tilt up, often can take longer than 30 seconds
12
14
13
15
# set defaults
14
16
settings = {
@@ -26,10 +28,12 @@ settings = {
26
28
keys = ["GCP_B64ENCODED_CREDENTIALS" ]
27
29
28
30
# global settings
29
- settings .update (read_json (
30
- "tilt-settings.json" ,
31
- default = {},
32
- ))
31
+ settings .update (
32
+ read_json (
33
+ "tilt-settings.json" ,
34
+ default = {},
35
+ )
36
+ )
33
37
34
38
if settings .get ("trigger_mode" ) == "manual" :
35
39
trigger_mode (TRIGGER_MODE_MANUAL )
@@ -40,36 +44,61 @@ if "allowed_contexts" in settings:
40
44
if "default_registry" in settings :
41
45
default_registry (settings .get ("default_registry" ))
42
46
47
+
43
48
# deploy CAPI
44
49
def deploy_capi ():
45
50
version = settings .get ("capi_version" )
46
- capi_uri = "https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml" .format (version )
47
- cmd = "curl -sSL {} | {} | {} apply -f -" .format (capi_uri , envsubst_cmd , kubectl_cmd )
48
- local (cmd , quiet = True )
51
+ capi_uri = "https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml" .format (
52
+ version
53
+ )
54
+ cmd = "curl -sSL {} | {} | {} apply -f -" .format (
55
+ capi_uri , envsubst_cmd , kubectl_cmd
56
+ )
57
+ local (cmd , quiet = True )
49
58
if settings .get ("extra_args" ):
50
59
extra_args = settings .get ("extra_args" )
51
60
if extra_args .get ("core" ):
52
61
core_extra_args = extra_args .get ("core" )
53
62
if core_extra_args :
54
63
for namespace in ["capi-system" ]:
55
- patch_args_with_extra_args (namespace , "capi-controller-manager" , core_extra_args )
64
+ patch_args_with_extra_args (
65
+ namespace , "capi-controller-manager" , core_extra_args
66
+ )
56
67
if extra_args .get ("kubeadm-bootstrap" ):
57
68
kb_extra_args = extra_args .get ("kubeadm-bootstrap" )
58
69
if kb_extra_args :
59
- patch_args_with_extra_args ("capi-kubeadm-bootstrap-system" , "capi-kubeadm-bootstrap-controller-manager" , kb_extra_args )
70
+ patch_args_with_extra_args (
71
+ "capi-kubeadm-bootstrap-system" ,
72
+ "capi-kubeadm-bootstrap-controller-manager" ,
73
+ kb_extra_args ,
74
+ )
75
+
60
76
61
77
def patch_args_with_extra_args (namespace , name , extra_args ):
62
- args_str = str (local ("{} get deployments {} -n {} -o jsonpath={{.spec.template.spec.containers[0].args}}" .format (kubectl_cmd , name , namespace )))
78
+ args_str = str (
79
+ local (
80
+ "{} get deployments {} -n {} -o jsonpath={{.spec.template.spec.containers[0].args}}" .format (
81
+ kubectl_cmd , name , namespace
82
+ )
83
+ )
84
+ )
63
85
args_to_add = [arg for arg in extra_args if arg not in args_str ]
64
86
if args_to_add :
65
87
args = args_str [1 :- 1 ].split ()
66
88
args .extend (args_to_add )
67
- patch = [{
68
- "op" : "replace" ,
69
- "path" : "/spec/template/spec/containers/0/args" ,
70
- "value" : args ,
71
- }]
72
- local ("{} patch deployment {} -n {} --type json -p='{}'" .format (kubectl_cmd , name , namespace , str (encode_json (patch )).replace ("\n " , "" )))
89
+ patch = [
90
+ {
91
+ "op" : "replace" ,
92
+ "path" : "/spec/template/spec/containers/0/args" ,
93
+ "value" : args ,
94
+ }
95
+ ]
96
+ local (
97
+ "{} patch deployment {} -n {} --type json -p='{}'" .format (
98
+ kubectl_cmd , name , namespace , str (encode_json (patch )).replace ("\n " , "" )
99
+ )
100
+ )
101
+
73
102
74
103
# Users may define their own Tilt customizations in tilt.d. This directory is excluded from git and these files will
75
104
# not be checked in to version control.
@@ -78,23 +107,37 @@ def include_user_tilt_files():
78
107
for f in user_tiltfiles :
79
108
include (f )
80
109
81
- def append_arg_for_container_in_deployment (yaml_stream , name , namespace , contains_image_name , args ):
110
+
111
+ def append_arg_for_container_in_deployment (
112
+ yaml_stream , name , namespace , contains_image_name , args
113
+ ):
82
114
for item in yaml_stream :
83
- if item ["kind" ] == "Deployment" and item .get ("metadata" ).get ("name" ) == name and item .get ("metadata" ).get ("namespace" ) == namespace :
115
+ if (
116
+ item ["kind" ] == "Deployment"
117
+ and item .get ("metadata" ).get ("name" ) == name
118
+ and item .get ("metadata" ).get ("namespace" ) == namespace
119
+ ):
84
120
containers = item .get ("spec" ).get ("template" ).get ("spec" ).get ("containers" )
85
121
for container in containers :
86
122
if contains_image_name in container .get ("image" ):
87
123
container .get ("args" ).extend (args )
88
124
125
+
89
126
def fixup_yaml_empty_arrays (yaml_str ):
90
127
yaml_str = yaml_str .replace ("conditions: null" , "conditions: []" )
91
128
return yaml_str .replace ("storedVersions: null" , "storedVersions: []" )
92
129
130
+
93
131
def validate_auth ():
94
132
substitutions = settings .get ("kustomize_substitutions" , {})
95
133
missing = [k for k in keys if k not in substitutions ]
96
134
if missing :
97
- fail ("missing kustomize_substitutions keys {} in tilt-settings.json" .format (missing ))
135
+ fail (
136
+ "missing kustomize_substitutions keys {} in tilt-settings.json" .format (
137
+ missing
138
+ )
139
+ )
140
+
98
141
99
142
tilt_helper_dockerfile_header = """
100
143
# Tilt image
@@ -118,35 +161,58 @@ COPY --from=tilt-helper /go/bin/dlv .
118
161
COPY manager .
119
162
"""
120
163
164
+
121
165
# Build CAPG and add feature gates
122
166
def capg ():
123
167
# Apply the kustomized yaml for this provider
124
168
substitutions = settings .get ("kustomize_substitutions" , {})
125
169
os .environ .update (substitutions )
126
170
127
- # yaml = str(kustomizesub("./hack/observability")) # build an observable kind deployment by default
128
- yaml = str (kustomizesub ("./config/default" ))
171
+ yaml = str (
172
+ kustomizesub ("./hack/observability" )
173
+ ) # build an observable kind deployment by default
174
+ # TODO: consider to remove
175
+ # yaml = str(kustomizesub("./config/default"))
129
176
130
177
# add extra_args if they are defined
131
178
if settings .get ("extra_args" ):
132
179
gcp_extra_args = settings .get ("extra_args" ).get ("gcp" )
133
180
if gcp_extra_args :
134
181
yaml_dict = decode_yaml_stream (yaml )
135
- append_arg_for_container_in_deployment (yaml_dict , "capg-controller-manager" , "capg-system" , "cluster-api-gcp-controller" , gcp_extra_args )
182
+ append_arg_for_container_in_deployment (
183
+ yaml_dict ,
184
+ "capg-controller-manager" ,
185
+ "capg-system" ,
186
+ "cluster-api-gcp-controller" ,
187
+ gcp_extra_args ,
188
+ )
136
189
yaml = str (encode_yaml_stream (yaml_dict ))
137
190
yaml = fixup_yaml_empty_arrays (yaml )
138
191
139
192
# Set up a local_resource build of the provider's manager binary.
140
193
local_resource (
141
194
"manager" ,
142
- cmd = 'mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \' -extldflags "-static"\' -o .tiltbuild/manager' ,
143
- deps = ["api" , "cloud" , "config" , "controllers" , "exp" , "feature" , "pkg" , "go.mod" , "go.sum" , "main.go" ],
195
+ cmd = "mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \" -static\" ' -o .tiltbuild/manager" ,
196
+ deps = [
197
+ "api" ,
198
+ "cloud" ,
199
+ "config" ,
200
+ "controllers" ,
201
+ "exp" ,
202
+ "feature" ,
203
+ "pkg" ,
204
+ "go.mod" ,
205
+ "go.sum" ,
206
+ "main.go" ,
207
+ ],
144
208
)
145
209
146
- dockerfile_contents = "\n " .join ([
147
- tilt_helper_dockerfile_header ,
148
- tilt_dockerfile_header ,
149
- ])
210
+ dockerfile_contents = "\n " .join (
211
+ [
212
+ tilt_helper_dockerfile_header ,
213
+ tilt_dockerfile_header ,
214
+ ]
215
+ )
150
216
151
217
entrypoint = ["sh" , "/start.sh" , "/manager" ]
152
218
extra_args = settings .get ("extra_args" )
@@ -156,45 +222,110 @@ def capg():
156
222
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
157
223
# build into the container.
158
224
docker_build (
159
- ref = "gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller" ,
160
- context = "./.tiltbuild/" ,
161
- dockerfile_contents = dockerfile_contents ,
162
- target = "tilt" ,
163
- entrypoint = entrypoint ,
164
- only = "manager" ,
165
- live_update = [
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 = [
166
232
sync (".tiltbuild/manager" , "/manager" ),
167
233
run ("sh /restart.sh" ),
168
234
],
169
- ignore = ["templates" ],
235
+ ignore = ["templates" ],
170
236
)
171
237
172
238
k8s_yaml (blob (yaml ))
173
239
240
+
241
+ def observability ():
242
+ # Install the OpenTelemetry helm chart
243
+ gcp_project_id = os .getenv ("GCP_PROJECT_ID" , "" )
244
+
245
+ k8s_yaml (
246
+ helm (
247
+ "./hack/observability/opentelemetry/chart" ,
248
+ name = "opentelemetry-collector" ,
249
+ namespace = "capg-system" ,
250
+ values = ["./hack/observability/opentelemetry/values.yaml" ],
251
+ # refer https://github.com/helm/helm/issues/1987
252
+ set = [
253
+ "extraEnvs[0].name=GCP_PROJECT_ID" ,
254
+ "extraEnvs[0].value=" + gcp_project_id ,
255
+ ],
256
+ )
257
+ )
258
+
259
+ k8s_yaml (
260
+ helm (
261
+ "./hack/observability/jaeger/chart" ,
262
+ name = "jaeger-all-in-one" ,
263
+ namespace = "capg-system" ,
264
+ set = [
265
+ # TODO: consider to remove
266
+ # "crd.install=false",
267
+ # "rbac.create=false",
268
+ "resources.limits.cpu=200m" ,
269
+ "resources.limits.memory=256Mi" ,
270
+ ],
271
+ )
272
+ )
273
+
274
+ 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" )
279
+ ],
280
+ labels = ["observability" ],
281
+ )
282
+
283
+ k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
284
+
285
+
174
286
def base64_encode (to_encode ):
175
- encode_blob = local ("echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ), quiet = True )
287
+ encode_blob = local (
288
+ "echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ), quiet = True
289
+ )
176
290
return str (encode_blob )
177
291
292
+
178
293
def base64_encode_file (path_to_encode ):
179
- encode_blob = local ("cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ), quiet = True )
294
+ encode_blob = local (
295
+ "cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ), quiet = True
296
+ )
180
297
return str (encode_blob )
181
298
299
+
182
300
def read_file_from_path (path_to_read ):
183
- str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
301
+ str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
184
302
return str (str_blob )
185
303
304
+
186
305
def base64_decode (to_decode ):
187
- decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
306
+ decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
188
307
return str (decode_blob )
189
308
309
+
190
310
def kustomizesub (folder ):
191
- yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
311
+ yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
192
312
return yaml
193
313
314
+
194
315
def waitforsystem ():
195
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system" )
196
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system" )
197
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-system" )
316
+ local (
317
+ kubectl_cmd
318
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system"
319
+ )
320
+ local (
321
+ kubectl_cmd
322
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system"
323
+ )
324
+ local (
325
+ kubectl_cmd
326
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-system"
327
+ )
328
+
198
329
199
330
##############################
200
331
# Actual work happens here
@@ -213,4 +344,6 @@ deploy_capi()
213
344
214
345
capg ()
215
346
347
+ observability ()
348
+
216
349
waitforsystem ()
0 commit comments