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

🐛 pkg/crd: support validation on type alias to basic types #1078

Merged

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Oct 21, 2024

Fixes #1071

Without the type Alias being its own type (Go 1.22 see gotypesalias), in localNamedToSchema, the link is missing.

[ Upstream port of d944deb ("Support type aliasing to basic types") ]

Previously, validation schema generation was skipped on a type alias:

type A = B

Whereas, a new type was fine:

type A B

This commit implements support for generating validation schemas for type aliases to basic types, i.e. string, int, etc.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 21, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @mtardy. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 21, 2024
mtardy and others added 2 commits October 21, 2024 13:10
Without the type Alias being its own type (Go 1.22 see gotypesalias), in
localNamedToSchema, the link is missing.

[ Upstream port of cilium/controller-tools@d944debcff34 ("Support type
aliasing to basic types") ]

Previously, validation schema generation was skipped on a type alias:

	type A = B

Whereas, a new type was fine:

	type A B

This commit implements support for generating validation schemas for
type aliases to basic types, i.e. string, int, etc.

Co-authored-by: Chris Tarazi <tarazichris@gmail.com>
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
This patch will be needed when upgrading to Go 1.23 as type alias now
generate a proper type (instead of directly being the basic type they
alias to), see https://pkg.go.dev/go/types#Alias for more info.

This just reproduces the old behavior by retrieving the underlying type
from the alias. If needed, we could treat alias more gracefully to make
the type ref link now that we have all the type information.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
@mtardy mtardy force-pushed the pr/mtardy/type-alias-validation branch from fc92564 to e443da3 Compare October 21, 2024 11:11
@mtardy
Copy link
Member Author

mtardy commented Oct 21, 2024

/cc @sbueringer

Since you commented here #1071 (comment).

@sbueringer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 25, 2024
@sbueringer
Copy link
Member

Thank you very much!!

/lgtm
/approve

@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: 8cde2ff060f2cedfdd25b0ed7bcbb387098d501d

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtardy, 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:

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 25, 2024
@k8s-ci-robot k8s-ci-robot merged commit 49ae6f8 into kubernetes-sigs:main Oct 25, 2024
9 checks passed
@mtardy mtardy deleted the pr/mtardy/type-alias-validation branch October 25, 2024 15:17
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

validation on type alias is ignored when GODEBUG=gotypealias=0 (Go < 1.23)
3 participants