Skip to content

Broken ApplyConfiguration when embedding an external struct #1298

@piepmatz

Description

@piepmatz

In the following scenario of embedding an external struct the generated applyconfiguration does not compile:

controller-tools versions: v0.19.0, main @ bf7d6b7

api/v1/foo_types.go:

type FooSpec struct {
  corev1.LocalObjectReference `json:",inline"`
}

api/v1/applyconfiguration/api/v1/foospec.go:

func (b *FooSpecApplyConfiguration) WithName(value string) *FooSpecApplyConfiguration {
	b.LocalObjectReference.Name = &value
	return b
}

Error: Cannot use '&value' (type *string) as the type string

Without embedding it works on first glance:

api/v1/foo_types.go:

type FooSpec struct {
  Ref corev1.LocalObjectReference `json:",inline"`
}

api/v1/applyconfiguration/api/v1/foospec.go:

func (b *FooSpecApplyConfiguration) WithRef(value v1.LocalObjectReference) *FooSpecApplyConfiguration {
	b.Ref = &value
	return b
}

However, this combination of not embedding the field but using json:",inline" (to keep the previous CRD schema) generates undesired content when marshaling the spec with encoding/json, as json:",inline" is ignored, making the kube-apiserver emit the warning unknown field "spec.Ref"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions