carvel-dev / carvel-dev/ytt

overlay/match's `by` does not accept a string when applied to a document

Open
#303 2 comments 1 reaction 0 assignees View on GitHub
bug carvel accepted priority/important-longterm
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

**What steps did you take:**
```yaml
#@ load("@ytt:overlay", "overlay")
#@ load("@ytt:data", "data")
#@overlay/match by="kind"
---
kind: Deployment
spec:
template:
spec:
containers:
#@overlay/match by="name"
- name: frontend
image: #@ data.values.frontend.image
```

**What happened:**

> ```
> Expected 'overlay/match' annotation keyword argument 'by' to be function, but was starlark.String
> ```

https://kubernetes.slack.com/archives/CH8KCCKA5/p1613490488283300?thread_ts=1613471663.281200&cid=CH8KCCKA5

**What did you expect:**

To behave identically to:

```yaml
#@ load("@ytt:overlay", "overlay")
#@ load("@ytt:data", "data")
#@overlay/match by=overlay.map_key("kind")
---
kind: Deployment
spec:
template:
spec:
containers:
#@overlay/match by="name"
- name: frontend
image: #@ data.values.frontend.image
```

It's particularly surprising that this works for the array, but not the document.

**Anything else you would like to add:**

As a matter of practical use, there's a risk that the user beginning with this short-hand will select more documents than they intend. Seems like it would be worth noting this in documentation/examples that illustrate use of this type of parameter on documents.

**Environment:**

- ytt version (use `ytt --version`): 0.31.0
- OS (e.g. from `/etc/os-release`): n/a

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the YAML example with ytt 0.31.0 and compare the document form with the working array form. Locate the overlay/match handling and its existing tests, then make the document shorthand accept a string consistently and add a regression test; done means the reproducer succeeds without changing the explicit map_key behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, yaml
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.