Unable to set property value to `nil` in golang
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
### Describe the bug
Using cdk8s, I want to set a specific property to have the YAML `null` value. Not seeing a way to do this.
### Expected Behavior
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
labels:
foo: bar
foo2: null
name: my-chart-my-cm-c841940f
```
### Current Behavior
```console
Synthesizing application
panic: parameter value is required, but nil was provided
goroutine 1 [running]:
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2.JsonPatch_Replace(0xc000014b80, {0x0, 0x0})
/Users/epolon/go/pkg/mod/github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2@v2.66.2/JsonPatch.go:168 +0x106
main.main()
/private/tmp/cdk8s-go/main.go:25 +0x2af
exit status 2
Error: command "go run . " at /private/tmp/cdk8s-go returned a non-zero exit code 1
at ChildProcess. (/opt/homebrew/lib/node_modules/cdk8s-cli/lib/util.js:54:27)
at Object.onceWrapper (node:events:634:26)
at ChildProcess.emit (node:events:519:28)
at ChildProcess._handle.onexit (node:internal/child_process:294:12)
```
### Reproduction Steps
```golang
package main
import (
"example.com/cdk8s-go/imports/k8s"
"github.com/aws/jsii-runtime-go"
"github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2"
)
func main() {
app := cdk8s.NewApp(&cdk8s.AppProps{})
chart := cdk8s.NewChart(app, jsii.String("my-chart"), &cdk8s.ChartProps{})
labels := map[string]*string{
"foo1": jsii.String("bar1"),
}
cm := k8s.NewKubeConfigMap(chart, jsii.String("my-cm"), &k8s.KubeConfigMapProps{
Metadata: &k8s.ObjectMeta{
Labels: &labels,
}})
app.Synth()
cm.AddJsonPatch(cdk8s.JsonPatch_Add(jsii.String("/metadata/labels/foo2"), nil))
}
```
### Possible Solution
_No response_
### Additional Information/Context
https://github.com/cdk8s-team/cdk8s/issues/2162
### SDK version used
```json
"jsii-pacmak": "^1.98.0",
"jsii-rosetta": "^5.4.21",
"jsii-srcmak": "^0.1.1142",
```
### Environment details (OS name and version, etc.)
Darwin bcd07455aba8 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64
Contributor guide
Research direction
Start with the cdk8s.JsonPatch_Add call in the provided main.go reproduction and inspect the generated cdk8s/v2 JsonPatch.go around line 168, where nil causes the panic. Trace how jsii represents a nil value across the Go binding, then verify that synthesis produces a YAML null at /metadata/labels/foo2 without panicking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, typescript
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100