Skip to content

Commit dd3c251

Browse files
authored
Merge pull request #6133 from schrej/tilt/yaml-config
🌱 tilt: switch to yaml for configuration
2 parents 5a4d139 + e6b7297 commit dd3c251

File tree

3 files changed

+75
-68
lines changed

3 files changed

+75
-68
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ vendor
6161
# User-supplied Tiltfile extensions, settings, and builds
6262
tilt.d
6363
tilt-settings.json
64+
tilt-settings.yaml
6465
.tiltbuild
6566

6667
# User-supplied clusterctl hacks settings

Tiltfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ settings = {
1111
}
1212

1313
# global settings
14-
settings.update(read_json(
15-
"tilt-settings.json",
14+
settings.update(read_yaml(
15+
"./tilt-settings.yaml" if os.path.exists("./tilt-settings.yaml") else "./tilt-settings.json",
1616
default = {},
1717
))
1818

@@ -119,8 +119,10 @@ def load_provider_tiltfiles():
119119
provider_repos = settings.get("provider_repos", [])
120120

121121
for repo in provider_repos:
122-
file = repo + "/tilt-provider.json"
123-
provider_details = read_json(file, default = {})
122+
file = repo + "/tilt-provider.yaml" if os.path.exists(repo + "/tilt-provider.yaml") else repo + "/tilt-provider.json"
123+
if not os.path.exists(file):
124+
fail("Failed to load provider. No tilt-provider.{yaml|json} file found in " + repo)
125+
provider_details = read_yaml(file, default = {})
124126
if type(provider_details) != type([]):
125127
provider_details = [provider_details]
126128
for item in provider_details:
@@ -356,6 +358,8 @@ def prepare_all():
356358
providers_arg = ""
357359
for name in get_providers():
358360
p = providers.get(name)
361+
if p == None:
362+
fail("Provider with name " + name + " not found")
359363
if p.get("kustomize_config", True):
360364
context = p.get("context")
361365
debug = ""

docs/book/src/developer/tilt.md

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,28 @@ You can see the status of the cluster with:
3535
kubectl cluster-info --context kind-capi-test
3636
```
3737

38-
### Create a tilt-settings.json file
38+
### Create a tilt-settings file
39+
40+
Next, create a `tilt-settings.yaml` file and place it in your local copy of `cluster-api`. Here is an example:
41+
42+
```yaml
43+
default_registry: gcr.io/your-project-name-here
44+
provider_repos:
45+
- ../cluster-api-provider-aws
46+
enable_providers":
47+
- aws
48+
- docker
49+
- kubeadm-bootstrap
50+
- kubeadm-control-plane
51+
```
3952
40-
Next, create a `tilt-settings.json` file and place it in your local copy of `cluster-api`. Here is an example:
53+
<aside class="note">
4154
42-
```json
43-
{
44-
"default_registry": "gcr.io/your-project-name-here",
45-
"provider_repos": ["../cluster-api-provider-aws"],
46-
"enable_providers": ["aws", "docker", "kubeadm-bootstrap", "kubeadm-control-plane"]
47-
}
48-
```
55+
If you prefer JSON, you can create a `tilt-settings.json` file instead. YAML will be preferred if both files are present.
56+
57+
</aside>
4958
50-
#### tilt-settings.json fields
59+
#### tilt-settings fields
5160
5261
**allowed_contexts** (Array, default=[]): A list of kubeconfig contexts Tilt is allowed to use. See the Tilt documentation on
5362
[allow_k8s_contexts](https://docs.tilt.dev/api.html#api.allow_k8s_contexts) for more details.
@@ -56,7 +65,7 @@ Next, create a `tilt-settings.json` file and place it in your local copy of `clu
5665
documentation](https://docs.tilt.dev/api.html#api.default_registry) for more details.
5766
5867
**provider_repos** (Array[]String, default=[]): A list of paths to all the providers you want to use. Each provider must have a
59-
`tilt-provider.json` file describing how to build the provider.
68+
`tilt-provider.yaml` or `tilt-provider.json` file describing how to build the provider.
6069
6170
**enable_providers** (Array[]String, default=['docker']): A list of the providers to enable. See [available providers](#available-providers)
6271
for more details.
@@ -94,15 +103,13 @@ Supported settings:
94103
95104
Example: Using the configuration below:
96105
97-
```json
98-
"debug": {
99-
"core": {
100-
"continue": false,
101-
"port": 30000,
102-
"profiler_port": 40000,
103-
"metrics_port": 40001
104-
}
105-
},
106+
```yaml
107+
debug:
108+
core:
109+
continue: false
110+
port: 30000
111+
profiler_port: 40000
112+
metrics_port: 40001
106113
```
107114
108115
##### Wiring up debuggers
@@ -140,10 +147,9 @@ Supported settings:
140147
141148
For example, if the yaml contains `${AWS_B64ENCODED_CREDENTIALS}`, you could do the following:
142149
143-
```json
144-
"kustomize_substitutions": {
145-
"AWS_B64ENCODED_CREDENTIALS": "your credentials here"
146-
}
150+
```yaml
151+
kustomize_substitutions:
152+
AWS_B64ENCODED_CREDENTIALS: "your credentials here"
147153
```
148154
149155
{{#/tab }}
@@ -172,26 +178,24 @@ An Azure Service Principal is needed for populating the controller manifests. Th
172178
AZURE_CLIENT_ID=$(az ad sp show --id http://$AZURE_SERVICE_PRINCIPAL_NAME --query appId --output tsv)
173179
```
174180
175-
Add the output of the following as a section in your `tilt-settings.json`:
181+
Add the output of the following as a section in your `tilt-settings.yaml`:
176182
177183
```shell
178184
cat <<EOF
179-
"kustomize_substitutions": {
180-
"AZURE_SUBSCRIPTION_ID_B64": "$(echo "${AZURE_SUBSCRIPTION_ID}" | tr -d '\n' | base64 | tr -d '\n')",
181-
"AZURE_TENANT_ID_B64": "$(echo "${AZURE_TENANT_ID}" | tr -d '\n' | base64 | tr -d '\n')",
182-
"AZURE_CLIENT_SECRET_B64": "$(echo "${AZURE_CLIENT_SECRET}" | tr -d '\n' | base64 | tr -d '\n')",
183-
"AZURE_CLIENT_ID_B64": "$(echo "${AZURE_CLIENT_ID}" | tr -d '\n' | base64 | tr -d '\n')"
184-
}
185+
kustomize_substitutions:
186+
AZURE_SUBSCRIPTION_ID_B64: "$(echo "${AZURE_SUBSCRIPTION_ID}" | tr -d '\n' | base64 | tr -d '\n')"
187+
AZURE_TENANT_ID_B64: "$(echo "${AZURE_TENANT_ID}" | tr -d '\n' | base64 | tr -d '\n')"
188+
AZURE_CLIENT_SECRET_B64: "$(echo "${AZURE_CLIENT_SECRET}" | tr -d '\n' | base64 | tr -d '\n')"
189+
AZURE_CLIENT_ID_B64: "$(echo "${AZURE_CLIENT_ID}" | tr -d '\n' | base64 | tr -d '\n')"
185190
EOF
186191
```
187192
188193
{{#/tab }}
189194
{{#tab DigitalOcean}}
190195
191-
```json
192-
"kustomize_substitutions": {
193-
"DO_B64ENCODED_CREDENTIALS": "your credentials here"
194-
}
196+
```yaml
197+
kustomize_substitutions:
198+
DO_B64ENCODED_CREDENTIALS: "your credentials here"
195199
```
196200
197201
{{#/tab }}
@@ -202,10 +206,9 @@ You can generate a base64 version of your GCP json credentials file using:
202206
base64 -i ~/path/to/gcp/credentials.json
203207
```
204208
205-
```json
206-
"kustomize_substitutions": {
207-
"GCP_B64ENCODED_CREDENTIALS": "your credentials here"
208-
}
209+
```yaml
210+
kustomize_substitutions:
211+
GCP_B64ENCODED_CREDENTIALS: "your credentials here"
209212
```
210213
211214
{{#/tab }}
@@ -223,14 +226,11 @@ for this provider. Each item in the array will be passed in to the manager for t
223226
224227
Example:
225228
226-
```json
227-
{
228-
"extra_args": {
229-
"core": ["--feature-gates=MachinePool=true"],
230-
"kubeadm-bootstrap": ["--feature-gates=MachinePool=true"],
231-
"azure": ["--feature-gates=MachinePool=true"]
232-
}
233-
}
229+
```yaml
230+
extra_args:
231+
core: ["--feature-gates=MachinePool=true"]
232+
kubeadm-bootstrap: ["--feature-gates=MachinePool=true"]
233+
azure: ["--feature-gates=MachinePool=true"]
234234
```
235235
236236
With this config, the respective managers will be invoked with:
@@ -274,23 +274,25 @@ The following providers are currently defined in the Tiltfile:
274274
* **core**: cluster-api itself (Cluster/Machine/MachineDeployment/MachineSet/KubeadmConfig/KubeadmControlPlane)
275275
* **docker**: Docker provider (DockerCluster/DockerMachine)
276276
277-
### tilt-provider.json
278-
279-
A provider must supply a `tilt-provider.json` file describing how to build it. Here is an example:
280-
281-
```json
282-
{
283-
"name": "aws",
284-
"config": {
285-
"image": "gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller",
286-
"live_reload_deps": [
287-
"main.go", "go.mod", "go.sum", "api", "cmd", "controllers", "pkg"
288-
]
289-
},
290-
"label": "CAPA"
291-
}
277+
### tilt-provider configuration
278+
279+
A provider must supply a `tilt-provider.yaml` file describing how to build it. Here is an example:
280+
281+
```yaml
282+
name: aws
283+
label: CAPA
284+
config:
285+
image: "gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller",
286+
live_reload_deps: ["main.go", "go.mod", "go.sum", "api", "cmd", "controllers", "pkg"]
292287
```
293288
289+
290+
<aside class="note">
291+
292+
If you prefer JSON, you can create a `tilt-provider.json` file instead. YAML will be preferred if both files are present.
293+
294+
</aside>
295+
294296
#### config fields
295297
296298
**image**: the image for this provider, as referenced in the kustomize files. This must match; otherwise, Tilt won't
@@ -337,13 +339,13 @@ is immediately before the "real work" happens.
337339
338340
At a high level, the Tiltfile performs the following actions:
339341
340-
1. Read `tilt-settings.json`
342+
1. Read `tilt-settings.yaml`
341343
1. Configure the allowed Kubernetes contexts
342344
1. Set the default registry
343345
1. Define the `providers` map
344346
1. Include user-defined Tilt files
345347
1. Deploy cert-manager
346-
1. Enable providers (`core` + what is listed in `tilt-settings.json`)
348+
1. Enable providers (`core` + what is listed in `tilt-settings.yaml`)
347349
1. Build the manager binary locally as a `local_resource`
348350
1. Invoke `docker_build` for the provider
349351
1. Invoke `kustomize` for the provider's `config/` directory

0 commit comments

Comments
 (0)