Skip to content

Go Operator : ObjectMeta struct in CRD spec leads to incorrect spec YAML generation #6558

@suneelkumarch

Description

@suneelkumarch

Bug Report

// WorkloadSpec defines the desired state of Workload
type FooSpec struct {
	FooTemplate appsv1.DeploymentSpec `json:"fooTemplate,omitempty"`
}

type Foo struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   FooSpec   `json:"spec,omitempty"`
	Status FooStatus  `json:"status,omitempty"`
}

Here FooTemplate is of type DeploymentSpec which contains a ObjectMeta in its PodTemplateSpec.
In the generated CRD yaml, PodTemplateSpec.ObjectMeta is turned-out as type object
image

When the CR is applied of type Foo, with foo.Spec.fooTemplate.template.metadata.labels` set as follows
image

following error is seen

error when creating "foo-cr.yaml": Foo in version "v1alpha1" cannot be handled as a Foo: strict decoding error: unknown field "spec.fooTemplate.template.metadata.labels"

What did you do?

Performed as described above

What did you expect to see?

CR of type Foo with '"spec.fooTemplate.template.metadata.labels"applied to cluster without an issue

What did you see instead? Under which circumstances?

Environment

Operator type:

/language go

Kubernetes cluster type:

minikube

$ operator-sdk version

operator-sdk version: "v1.22.2", commit: "da3346113a8a75e11225f586482934000504a60f", kubernetes version: "1.24.1", go version: "go1.18.4", GOOS: "linux", GOARCH: "amd64"

$ go version (if language is Go)

go version go1.20.6 linux/amd64
$ kubectl version

Client Version: v1.28.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.4

Possible Solution

Additional context

Metadata

Metadata

Labels

language/goIssue is related to a Go operator projectlifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.triage/needs-informationIndicates an issue needs more information in order to work on it.triage/supportIndicates an issue that is a support question.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions