kubernetes-sigs / kubernetes-sigs/structured-merge-diff

RemoveItems converts empty maps and lists ({} and []) instead to null

Open
#305 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
137
Forks
73
Avg merge
53m
Merged PRs (30d)
12

Description

I'm experiencing a similar issue as https://github.com/kubernetes-sigs/structured-merge-diff/pull/302 except for `RemoveItems()`

For example in my CronJob jobTempalte i end up with a metadata: null which is not a nullable field

```
"spec": {
"concurrencyPolicy": "Allow",
"failedJobsHistoryLimit": 1,
"jobTemplate": {
"metadata": null,
```
We should do the same as Extract items and preserve empty list/maps
```
# Starting value
mapOfMaps:
b:
a: "x"
c: "z"

# Call RemoveItems to remove all nested fields
RemoveItems(mapOfMaps.b.a, mapOfMaps.b.c)

# BUG: Returns null
mapOfMaps:
b: null
```

In my case the list/map is not empty before calling RemoveItems(). Only after calling RemoveItems() then the list/map is empty and returns null.

I think the correct behavior is we preserve the list or map if it becomes empty after using RemoveItems

Contributor guide

Open the contributing guide

Research direction

Start by comparing RemoveItems with ExtractItems and the behavior described in pull request 302. Add regression coverage for removing all nested fields while preserving an empty map or list, then verify the result no longer becomes null in the shown mapOfMaps and CronJob cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.