Skip to content

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

Merged
k8s-ci-robot merged 2 commits intokubernetes-sigs:mainfrom
mtardy:pr/mtardy/type-alias-validation
Oct 25, 2024
Merged

🐛 pkg/crd: support validation on type alias to basic types#1078
k8s-ci-robot merged 2 commits intokubernetes-sigs:mainfrom
mtardy:pr/mtardy/type-alias-validation

Conversation

@mtardy
Copy link
Copy Markdown
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
Copy Markdown
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.

Details

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
Copy Markdown
Member Author

mtardy commented Oct 21, 2024

/cc @sbueringer

Since you commented here #1071 (comment).

@sbueringer
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 8cde2ff060f2cedfdd25b0ed7bcbb387098d501d

@k8s-ci-robot
Copy link
Copy Markdown
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

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 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
@mtardy mtardy deleted the pr/mtardy/type-alias-validation branch October 25, 2024 15:17
sayboras pushed a commit to cilium/cilium that referenced this pull request Mar 19, 2025
This closes off GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Signed-off-by: Tam Mach <tam.mach@cilium.io>
ferozsalam added a commit to cilium/cilium that referenced this pull request Mar 20, 2025
This closes off GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Signed-off-by: Tam Mach <tam.mach@cilium.io>
ferozsalam added a commit to cilium/cilium that referenced this pull request Mar 20, 2025
This resolves GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Co-authored-by: Tam Mach <tam.mach@cilium.io>
github-merge-queue bot pushed a commit to cilium/cilium that referenced this pull request Mar 20, 2025
This closes off GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Signed-off-by: Tam Mach <tam.mach@cilium.io>
ferozsalam added a commit to cilium/cilium that referenced this pull request Mar 21, 2025
This resolves GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Co-authored-by: Tam Mach <tam.mach@cilium.io>
julianwiedmann pushed a commit to cilium/cilium that referenced this pull request Mar 21, 2025
This resolves GHSA-qxp5-gwg8-xv66

Just a note that go 1.23 type alias breaks controller-tools code
generation, so gotypesalias=0 is set to keep the same behavior in go
1.22.

Relates: kubernetes-sigs/controller-tools#1078
Relates: #35406

Signed-off-by: Feroz Salam <feroz.salam@isovalent.com>
Co-authored-by: Tam Mach <tam.mach@cilium.io>
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