@@ -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
@@ -113,35 +156,58 @@ COPY --from=tilt-helper /restart.sh .
113
156
COPY manager .
114
157
"""
115
158
159
+
116
160
# Build CAPG and add feature gates
117
161
def capg ():
118
162
# Apply the kustomized yaml for this provider
119
163
substitutions = settings .get ("kustomize_substitutions" , {})
120
164
os .environ .update (substitutions )
121
165
122
- # yaml = str(kustomizesub("./hack/observability")) # build an observable kind deployment by default
123
- yaml = str (kustomizesub ("./config/default" ))
166
+ yaml = str (
167
+ kustomizesub ("./hack/observability" )
168
+ ) # build an observable kind deployment by default
169
+ # TODO: consider to remove
170
+ # yaml = str(kustomizesub("./config/default"))
124
171
125
172
# add extra_args if they are defined
126
173
if settings .get ("extra_args" ):
127
174
gcp_extra_args = settings .get ("extra_args" ).get ("gcp" )
128
175
if gcp_extra_args :
129
176
yaml_dict = decode_yaml_stream (yaml )
130
- append_arg_for_container_in_deployment (yaml_dict , "capg-controller-manager" , "capg-system" , "cluster-api-gcp-controller" , gcp_extra_args )
177
+ append_arg_for_container_in_deployment (
178
+ yaml_dict ,
179
+ "capg-controller-manager" ,
180
+ "capg-system" ,
181
+ "cluster-api-gcp-controller" ,
182
+ gcp_extra_args ,
183
+ )
131
184
yaml = str (encode_yaml_stream (yaml_dict ))
132
185
yaml = fixup_yaml_empty_arrays (yaml )
133
186
134
187
# Set up a local_resource build of the provider's manager binary.
135
188
local_resource (
136
189
"manager" ,
137
- cmd = 'mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \' -extldflags "-static"\' -o .tiltbuild/manager' ,
138
- deps = ["api" , "cloud" , "config" , "controllers" , "exp" , "feature" , "pkg" , "go.mod" , "go.sum" , "main.go" ],
190
+ cmd = "mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags \" -static\" ' -o .tiltbuild/manager" ,
191
+ deps = [
192
+ "api" ,
193
+ "cloud" ,
194
+ "config" ,
195
+ "controllers" ,
196
+ "exp" ,
197
+ "feature" ,
198
+ "pkg" ,
199
+ "go.mod" ,
200
+ "go.sum" ,
201
+ "main.go" ,
202
+ ],
139
203
)
140
204
141
- dockerfile_contents = "\n " .join ([
142
- tilt_helper_dockerfile_header ,
143
- tilt_dockerfile_header ,
144
- ])
205
+ dockerfile_contents = "\n " .join (
206
+ [
207
+ tilt_helper_dockerfile_header ,
208
+ tilt_dockerfile_header ,
209
+ ]
210
+ )
145
211
146
212
entrypoint = ["sh" , "/start.sh" , "/manager" ]
147
213
extra_args = settings .get ("extra_args" )
@@ -151,45 +217,110 @@ def capg():
151
217
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
152
218
# build into the container.
153
219
docker_build (
154
- ref = "gcr.io/k8s-staging-cluster-api-gcp/cluster-api-gcp-controller" ,
155
- context = "./.tiltbuild/" ,
156
- dockerfile_contents = dockerfile_contents ,
157
- target = "tilt" ,
158
- entrypoint = entrypoint ,
159
- only = "manager" ,
160
- live_update = [
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 = [
161
227
sync (".tiltbuild/manager" , "/manager" ),
162
228
run ("sh /restart.sh" ),
163
229
],
164
- ignore = ["templates" ],
230
+ ignore = ["templates" ],
165
231
)
166
232
167
233
k8s_yaml (blob (yaml ))
168
234
235
+
236
+ def observability ():
237
+ # Install the OpenTelemetry helm chart
238
+ gcp_project_id = os .getenv ("GCP_PROJECT_ID" , "" )
239
+
240
+ k8s_yaml (
241
+ helm (
242
+ "./hack/observability/opentelemetry/chart" ,
243
+ name = "opentelemetry-collector" ,
244
+ namespace = "capg-system" ,
245
+ values = ["./hack/observability/opentelemetry/values.yaml" ],
246
+ # refer https://github.com/helm/helm/issues/1987
247
+ set = [
248
+ "extraEnvs[0].name=GCP_PROJECT_ID" ,
249
+ "extraEnvs[0].value=" + gcp_project_id ,
250
+ ],
251
+ )
252
+ )
253
+
254
+ k8s_yaml (
255
+ helm (
256
+ "./hack/observability/jaeger/chart" ,
257
+ name = "jaeger-all-in-one" ,
258
+ namespace = "capg-system" ,
259
+ set = [
260
+ # TODO: consider to remove
261
+ # "crd.install=false",
262
+ # "rbac.create=false",
263
+ "resources.limits.cpu=200m" ,
264
+ "resources.limits.memory=256Mi" ,
265
+ ],
266
+ )
267
+ )
268
+
269
+ 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" )
274
+ ],
275
+ labels = ["observability" ],
276
+ )
277
+
278
+ k8s_resource (workload = "opentelemetry-collector" , labels = ["observability" ])
279
+
280
+
169
281
def base64_encode (to_encode ):
170
- encode_blob = local ("echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ), quiet = True )
282
+ encode_blob = local (
283
+ "echo '{}' | tr -d '\n ' | base64 - | tr -d '\n '" .format (to_encode ), quiet = True
284
+ )
171
285
return str (encode_blob )
172
286
287
+
173
288
def base64_encode_file (path_to_encode ):
174
- encode_blob = local ("cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ), quiet = True )
289
+ encode_blob = local (
290
+ "cat {} | tr -d '\n ' | base64 - | tr -d '\n '" .format (path_to_encode ), quiet = True
291
+ )
175
292
return str (encode_blob )
176
293
294
+
177
295
def read_file_from_path (path_to_read ):
178
- str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
296
+ str_blob = local ("cat {} | tr -d '\n '" .format (path_to_read ), quiet = True )
179
297
return str (str_blob )
180
298
299
+
181
300
def base64_decode (to_decode ):
182
- decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
301
+ decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
183
302
return str (decode_blob )
184
303
304
+
185
305
def kustomizesub (folder ):
186
- yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
306
+ yaml = local ("hack/kustomize-sub.sh {}" .format (folder ), quiet = True )
187
307
return yaml
188
308
309
+
189
310
def waitforsystem ():
190
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system" )
191
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system" )
192
- local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-system" )
311
+ local (
312
+ kubectl_cmd
313
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system"
314
+ )
315
+ local (
316
+ kubectl_cmd
317
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system"
318
+ )
319
+ local (
320
+ kubectl_cmd
321
+ + " wait --for=condition=ready --timeout=300s pod --all -n capi-system"
322
+ )
323
+
193
324
194
325
##############################
195
326
# Actual work happens here
@@ -208,4 +339,6 @@ deploy_capi()
208
339
209
340
capg ()
210
341
342
+ observability ()
343
+
211
344
waitforsystem ()
0 commit comments