aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.63k stars 244 forks source link

Unable to set property value to `nil` in golang #4529

Open iliapolo opened 3 months ago

iliapolo commented 3 months ago

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

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    foo: bar
    foo2: null
  name: my-chart-my-cm-c841940f

Current Behavior

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.<anonymous> (/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

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

    "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