Skip to content

JSON marshalling not working with the inline and omitempty options #161

@TheBigLee

Description

@TheBigLee

What happened?

When you use a specific field in a resource that has the inline and the omitempty field specified, the json marshaling will fail with the error:

json: cannot marshal Go value of type v1beta1.DataKeySelector: Go struct field
      NamespacedName cannot have any options other than `inline` or `unknown` specified'

This error is for example triggered when using the set field of a release using provider-helm

How can we reproduce it?

  • Have a v1beta1.Release from provider-helm
  • Have a SetVal object in the release like this:
v1beta1.Release{
  Spec: v1beta1.ReleaseSpec{
    ForProvider: v1beta1.ReleaseParameters{
      ValuesSpec: v1beta1.ValuesSpec{
        Set: []v1beta1.SetVal{
          {
            Name: "password",
            ValueFrom: &v1beta1.ValueFromSource{
              SecretKeyRef: &v1beta1.DataKeySelector{
                NamespacedName: v1beta1.NamespacedName{
                  Namespace: "foo",
                  Name: "bar",
                },
                Key: "password",
              },
            },
          },
        },
      },
    },
  },
}

Why does this fail?
The NamespacedName field in provider-helm has the following json fields: ,inline,omitempty (see: https://github.com/crossplane-contrib/provider-helm/blob/main/apis/release/v1beta1/types.go#L50)
However, this is currently not supported by the json-library used in this function-sdk-go (see: https://github.com/go-json-experiment/json/blob/master/fields.go#L105-L111)

The error is triggered by calling the json.Marshal() function here: https://github.com/crossplane/function-sdk-go/blob/v0.3.0-rc.0/resource/composed/composed.go#L76

What environment did it happen in?

Crossplane version: 1.17
Provider-Helm: v0.19.0
Function-sdk-go: v0.3.0-rc.0
go-json-experiment: v0.0.0-20231102232822-2e55bd4e08b0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions