carvel-dev / carvel-dev/ytt

#@overlay/insert inserts out of order

Open
#308 3 comments 0 reactions 0 assignees View on GitHub
bug can be replicated carvel accepted
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

ℹ️ This bug should be addressed by implementing #371. See _that_ story for details.

Original Report 👇🏻
---

**What steps did you take:**
Ran the following files through ytt:
```yaml
#! template.yaml

non-empty: doc
---
array:
- seeded
```

```yaml
#! overlay.yaml

#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all, expects="1+"
---
#@overlay/match missing_ok=True
array:
#@overlay/append
- appended
#@overlay/match by=overlay.index(0)
#@overlay/insert before=True
- inserted before 0
```

**What happened:**
The command executed successfully, and output this yaml:
```yaml
non-empty: doc
array:
- appended
- inserted before 0
---
array:
- inserted before 0
- seeded
- appended
```

Note the order of the items in the array. The "inserted before 0" item is added after the "appended" item in the first document, but (properly) before in the second.

**Anything else you would like to add:**
This doesn't occur if we insert an array key to the first doc
```yaml
non-empty: doc
array: []
```

which gets properly templated as:
```yaml
non-empty: doc
array:
- inserted before 0
- appended
```

**Environment:**

- ytt version (use `ytt --version`): This occurs on the playground at 0.30.0 as well as local dev at 0.31.0
- OS (e.g. from `/etc/os-release`): MacOS

Contributor guide

Open the contributing guide

Research direction

Issue #371 is identified as the intended fix; read that story first. Reproduce the behavior with template.yaml and overlay.yaml using ytt, focusing on the differing array order when the array is absent versus initialized. Done means the inserted item precedes the appended item in both outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.