Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix item validation for unhashable markers #1080

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Oct 25, 2024

Signed-off-by: Stefan Büringer buringerst@vmware.com

Today items validation with unhasable markers is broken (e.g. enum).

Example:

	// This tests slice item validation with enum
	// +kubebuilder:validation:items:Enum=0;1;3
	EnumSlice []int `json:"enumSlice,omitempty"`

Leads to the following error

panic: runtime error: hash of unhashable type markers.Enum

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.applyMarkers(0x1400bdab4a8, 0x140035f2270, 0x14013acd400, {0x104b57828, 0x140021ce240})
        /Users/buringerst/code/src/sigs.k8s.io/controller-tools/pkg/crd/schema.go:139 +0x784
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x1400bdab4a8, 0x140032104c8)
        /Users/buringerst/code/src/sigs.k8s.io/controller-tools/pkg/crd/schema.go:458 +0x824
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400bdab4a8, {0x104b5a4d0, 0x140032104c8})
        /Users/buringerst/code/src/sigs.k8s.io/controller-tools/pkg/crd/schema.go:207 +0x90

Signed-off-by: Stefan Büringer buringerst@vmware.com
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 25, 2024
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 25, 2024

for markerName, markerValues := range markerSet {
for _, markerValue := range markerValues {
if schemaMarker, isSchemaMarker := markerValue.(SchemaMarker); isSchemaMarker {
if strings.HasPrefix(markerName, crdmarkers.ValidationItemsPrefix) {
itemsMarkers = append(itemsMarkers, schemaMarker)
itemsMarkerNames[schemaMarker] = markerName
Copy link
Member Author

Choose a reason for hiding this comment

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

This line failed if a marker is unhashable (e.g. Enum)

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 25, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: bbaf90701b62d2fd080364b56706b2309fcb3db0

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, sbueringer

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:
  • OWNERS [alvaroaleman,sbueringer]

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 merged commit 5ea1855 into kubernetes-sigs:main Oct 25, 2024
12 checks passed
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants