11# -*- mode: Python -*-
22
3- # set defaults
3+ kustomize_cmd = "./hack/tools/bin/kustomize"
4+ envsubst_cmd = "./hack/tools/bin/envsubst"
5+
6+ update_settings (k8s_upsert_timeout_secs = 60 ) # on first tilt up, often can take longer than 30 seconds
47
8+ # set defaults
59settings = {
610 "allowed_contexts" : [
711 "kind-capz"
@@ -53,7 +57,9 @@ def deploy_cert_manager():
5357# deploy CAPI
5458def deploy_capi ():
5559 version = settings .get ("capi_version" )
56- local ("kubectl apply -f https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml" .format (version ))
60+ capi_uri = "https://github.com/kubernetes-sigs/cluster-api/releases/download/{}/cluster-api-components.yaml" .format (version )
61+ cmd = "curl -sSL {} | {} | kubectl apply -f -" .format (capi_uri , envsubst_cmd )
62+ local (cmd , quiet = True )
5763 if settings .get ("extra_args" ):
5864 extra_args = settings .get ("extra_args" )
5965 if extra_args .get ("core" ):
@@ -142,6 +148,7 @@ COPY --from=tilt-helper /restart.sh .
142148COPY manager .
143149"""
144150
151+
145152# Build CAPZ and add feature gates
146153def capz ():
147154 # Apply the kustomized yaml for this provider
@@ -164,7 +171,7 @@ def capz():
164171 local_resource (
165172 "manager" ,
166173 cmd = 'mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \' -extldflags "-static"\' -o .tiltbuild/manager' ,
167- deps = ["./ api" , "./main.go " , "./ pkg" , "./controllers " , "./cloud " , "./exp " ]
174+ deps = ["api" , "cloud " , "config" , "controllers" , "exp" , "feature" , " pkg" , "go.mod " , "go.sum " , "main.go " ]
168175 )
169176
170177 dockerfile_contents = "\n " .join ([
@@ -187,11 +194,13 @@ def capz():
187194 entrypoint = entrypoint ,
188195 only = "manager" ,
189196 live_update = [
190- sync ("./. tiltbuild/manager" , "/manager" ),
197+ sync (".tiltbuild/manager" , "/manager" ),
191198 run ("sh /restart.sh" ),
192199 ],
200+ ignore = ["templates" ]
193201 )
194202
203+ yaml = envsubst (yaml )
195204 k8s_yaml (blob (yaml ))
196205
197206
@@ -270,11 +279,12 @@ def deploy_worker_templates(flavor, substitutions):
270279 value = substitutions [substitution ]
271280 yaml = yaml .replace ("${" + substitution + "}" , value )
272281
282+ yaml = envsubst (yaml )
273283 yaml = yaml .replace ('"' , '\\ "' ) # add escape character to double quotes in yaml
274284
275285 local_resource (
276286 "worker-" + flavor ,
277- cmd = "make generate-flavors; echo \" " + yaml + "\" > ./.tiltbuild/worker-" + flavor + ".yaml; kubectl apply -f ./.tiltbuild/worker-" + flavor + ".yaml" ,
287+ cmd = "make generate-flavors; echo \" " + yaml + "\" > ./.tiltbuild/worker-" + flavor + ".yaml; cat ./.tiltbuild/worker-" + flavor + ".yaml | " + envsubst_cmd + " | kubectl apply -f - " ,
278288 auto_init = False ,
279289 trigger_mode = TRIGGER_MODE_MANUAL
280290 )
@@ -323,6 +333,11 @@ def base64_decode(to_decode):
323333 decode_blob = local ("echo '{}' | base64 --decode -" .format (to_decode ), quiet = True )
324334 return str (decode_blob )
325335
336+
337+ def envsubst (yaml ):
338+ yaml = yaml .replace ('"' , '\\ "' )
339+ return str (local ("echo \" {}\" | {}" .format (yaml , envsubst_cmd ), quiet = True ))
340+
326341##############################
327342# Actual work happens here
328343##############################
0 commit comments