Skip to content

🐛 fix(crd): Fix duplicate MinProperties/MaxProperties#1398

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-uplciate-validations
Open

🐛 fix(crd): Fix duplicate MinProperties/MaxProperties#1398
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-uplciate-validations

Conversation

@camilamacedo86
Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 commented Apr 27, 2026

When a struct with +kubebuilder:validation:MinProperties=1 embeds another struct with the same setting, the CRD generates duplicates.

Example:

allOf:
  - minProperties: 1
  - minProperties: 1   # duplicate

This PR fixes this scenario and ensures that the duplication is removed.

Fixes: #1234

Assisted-by: Claude

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign alvaroaleman for approval. For more information see the Code Review Process.

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

Details 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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 27, 2026
@camilamacedo86 camilamacedo86 force-pushed the fix-uplciate-validations branch from 3834030 to 3765c8c Compare April 27, 2026 10:44
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 27, 2026
Comment thread pkg/crd/flatten.go
}

// resolveFieldConflict handles conflicts when both src and dst have values for a field
func resolveFieldConflict(fieldName string, srcField, dstField reflect.Value, srcInt, dstInt any, errRec ErrorRecorder, srcRemVal, dstRemVal reflect.Value, fieldIndex int) bool {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The only change here is where has // remove duplicate if values are identical
The rest is == but we need to add all to its func to fix the lint issue (reduces the complexity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

controller-gen does not deduplicate/flatten MinProperties with embedded struct

2 participants