Skip to content

Conversation

@camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Nov 15, 2025

Remove 'omitempty' from JSON tags on nested struct fields (metav1.ObjectMeta, Status, and metav1.ListMeta) in API type scaffolds. The 'omitempty' tag has no effect on nested structs in Go and triggers linter warnings.

For Go 1.24+, 'omitzero' correctly handles nested structs and omits them when empty, making 'omitempty' redundant and misleading. The '// +optional' markers already indicate optional fields for CRD schema generation.

Updated JSON tags:

  • metav1.ObjectMeta: json:"metadata,omitempty,omitzero" → json:"metadata,omitzero"
  • Status fields: json:"status,omitempty,omitzero" → json:"status,omitzero"
  • metav1.ListMeta: json:"metadata,omitempty" → json:"metadata,omitzero"

This resolves linter warnings from gopls modernise analyser and kube-api-linter while maintaining correct behaviour for projects using Go 1.24+.

Closes #5205

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 15, 2025
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 15, 2025
@camilamacedo86 camilamacedo86 changed the title 🐛 (go/v4;deploy-image/v1-alpha): Remove omitempty from nested struct … 🐛 (go/v4;deploy-image/v1-alpha): Remove omitempty from nested struct JSON tags in API scaffolds Nov 15, 2025
@camilamacedo86 camilamacedo86 force-pushed the fix-api-linter branch 2 times, most recently from 54c5cdb to 05c6b81 Compare November 15, 2025 06:54
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Nov 15, 2025
Remove omitempty from JSON tags on nested struct fields such as metav1 ObjectMeta Status and metav1 ListMeta in API type scaffolds

The omitempty tag has no effect on nested structs in Go and triggers linter warnings

For Go version 1.24+ and later omitzero correctly handles nested structs and omits them when empty making omitempty redundant and misleading The optional markers already indicate optional fields for CRD schema generation

Updated JSON tags:

- metav1 ObjectMeta metadata omitempty omitzero becomes metadata omitzero
- Status fields status omitempty omitzero becomes status omitzero
- metav1 ListMeta metadata omitempty becomes metadata omitzero

This resolves linter warnings from gopls modernize analyzer and kube api linter while maintaining correct behavior for projects using Go 1.24+

Signed-off-by: Camila Macedo <[email protected]>
@camilamacedo86
Copy link
Member Author

@JoelSpeed

Could you please give a hand on the review?

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afzal442, camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 15, 2025
@k8s-ci-robot k8s-ci-robot merged commit f148cd9 into kubernetes-sigs:master Nov 15, 2025
43 of 45 checks passed
@camilamacedo86 camilamacedo86 deleted the fix-api-linter branch November 15, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated API code cause warnings from modernize "omitzero" analizer

4 participants