ytt
ytt copied to clipboard
enhance structs to support iteration, bracket accessor, ...
currently we use struct package provided by starlark. it seems that it lacks few things that would make it friendlier to use (especially for case of data.values).
- [ ] support iteration (e.g.
for k in st
) - [ ] support [] accessor (e.g. st["foo"] in addition to st.foo)
- [ ]
in
check (e.g."foo" in st
) - [ ] anything else that we have done for yaml fragments https://github.com/k14s/ytt/blob/develop/pkg/yamltemplate/starlark_fragment.go?
Started working on this.
Thought I was done when struct.encode()
was working as described in this issue.
However, while writing up corresponding docs, discovered that struct.make()
is an entirely different code-path.
Will address that bit too.
Just noting here that iterating over maps for this use-case does appear to work properly with ytt 0.31.0.
#@data/values
---
env:
KUBE_SECRET: my-registry-token #! does not yet exist -- will be created in the same Namespace
SYNC_PERIOD: 3600 #! tokens expire; refresh faster than that
---
#! ... abbreviated
env:
#@ for k in data.values.env:
- name: #@ str(k)
value: #@ str(data.values.env[k])
#@ end
This is common with config for k8s Deployments.
I'm not knowledgeable whether maps and structs are similar or related in Starlark, and there may be other technicalities that mean they are not fully iterable yet.
Either way, this wasn't clear from these examples:
- https://carvel.dev/ytt/#example:example-for
- https://carvel.dev/ytt/#example:example-datatypes