struct.encode() should support YAML Fragments as values
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
Today:
```
#@ load("@ytt:struct", "struct")
#@ def labels():
foo: bar
#@ end
#@ env = struct.encode({"labels": labels()})
v: #@ env
```
results in ...
```
- (p) unknown type *yamlmeta.Map for conversion to starlark value (backtrace: goroutine 1 [running]:
in
demo.yml:7 | #@ env = struct.encode({"labels": labels()})
reason:
runtime/debug.Stack(0x934960, 0x8fef60, 0xc000160760)
runtime/debug/stack.go:24 +0x9d
github.com/k14s/ytt/pkg/template/core.ErrWrapper.func1.1(0xc00016eb78)
github.com/k14s/ytt@/pkg/template/core/errs.go:23 +0x158
panic(0x8fef60, 0xc000160760)
runtime/panic.go:679 +0x1b2
github.com/k14s/ytt/pkg/template/core.GoValue.asStarlarkValue(0x97f6a0, 0xc000178200, 0x1, 0x0, 0x99cac0, 0xc000167220, 0x8, 0x18)
...
```
Given that YAML Fragments are data structures, themselves (very similar to `struct`s), `struct.encode()` should include the YAML Fragment.
Contributor guide
Research direction
Start at struct.encode() and reproduce the example with labels() returning a YAML Fragment. Trace how struct.encode handles struct values and verify that the fragment is included without the unknown type error. Done means the shown input produces env with labels rather than failing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100