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

Add utils to translate custom types #1310

Closed

Conversation

abhijit-dev82
Copy link
Contributor

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Proposed change set are helper functions to translate to and from custom types.

Which issue(s) this PR fixes:
Fixes #826

Does this PR introduce a user-facing change?:
No

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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 Aug 11, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @abhijit-dev82. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 11, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: abhijit-dev82
Once this PR has been reviewed and has the lgtm label, please assign youngnick for approval by writing /assign @youngnick in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @abhijit-dev82! This looks like a great start. Will discuss this at the community meeting on Monday to ensure that at least some implementations will actually make use of this. This seems like it could be very helpful, but don't want to introduce extra code to maintain until we're sure it will be used.

return portNum
}

func ListenerHostnameToPtr(host string) *Hostname {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe remove Listener prefix here since Hostname can be used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

@@ -0,0 +1,177 @@
/*
Copyright 2020 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Copyright 2020 The Kubernetes Authors.
Copyright 2022 The Kubernetes Authors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected.

@@ -0,0 +1,177 @@
/*
Copyright 2020 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Copyright 2020 The Kubernetes Authors.
Copyright 2022 The Kubernetes Authors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

return portNum
}

func ListenerHostnameToPtr(host string) *Hostname {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe remove Listener prefix here since Hostname can be used elsewhere.


package v1beta1

func SectionNameToPtr(sectionName string) *SectionName {
Copy link
Member

Choose a reason for hiding this comment

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

I think most go linting will usually fail without comments describing each exported function

@carlisia
Copy link
Contributor

carlisia commented Aug 16, 2022

@abhijit-dev82 thank you for doing this, I will certainly use it so I can delete some code in my code base!

Everything lgtm except I'm not loving the name and the location of the file, especially when I consider existing helper functionality.

I opened an issue to explain: Consider a minor restructure of directory/file for util things · Issue #1336 · kubernetes-sigs/gateway-api. I'd hate to block the merging of this PR for something that is sorta trivial but brakes the interface so it will require some thinking. At the same time, I would love adding such helpful code in a place that makes great sense, given the context around it.

@robscott
Copy link
Member

I really like @carlisia's idea in #1336. @abhijit-dev82 do you think you could incorporate that restructuring into this PR?

/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 Aug 16, 2022
@carlisia
Copy link
Contributor

There is one more input I'd like to offer. If we look at the existing conversion helpers (PathMatchTypePtr and PortNumberPtr here:

func PathMatchTypePtr(s string) *gatewayv1a2.PathMatchType {

...we see that there is no To or From. That style is idiomatic of Go because it doesn't duplicate information that we can see in a different way. In this case, that PathMatchTypePtr takes a string is indicated in the signature, and it is idiomatic to name the function based on what it returns, in this case the pointer. Sooooo.... long paragraph to suggest changing the names to fit this format:

s/SectionNameToPtr/SectionNamePtr
s/SectionNameFromPtr/SectionNameStr

@carlisia
Copy link
Contributor

This PR adds the directory structure mentioned above: #1337.

@abhijit-dev82
Copy link
Contributor Author

@carlisia & @robscott Thank you for all the comments. I was away due to health reasons, hence was not able to make the necessary changes. I see that the directory changes are already done, will add the new file in the util dir. Do we need to see we can auto generate these translation routines based on the custom types defined .

@k8s-ci-robot
Copy link
Contributor

@abhijit-dev82: PR needs rebase.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 22, 2022
Add utils to translate custom types
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 22, 2022
@abhijit-dev82 abhijit-dev82 force-pushed the test-name-fix branch 2 times, most recently from a012b32 to b1640c1 Compare August 22, 2022 16:17
@k8s-ci-robot k8s-ci-robot removed the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 22, 2022
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 22, 2022
@k8s-ci-robot
Copy link
Contributor

@abhijit-dev82: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-gateway-api-verify b1640c1 link true /test pull-gateway-api-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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/test-infra repository. I understand the commands that are listed here.

@abhijit-dev82
Copy link
Contributor Author

HI @carlisia & @robscott , Had to open a new PR as was facing merge issues with the older branch. Below is the link
#1352

@abhijit-dev82 abhijit-dev82 deleted the test-name-fix branch August 25, 2022 13:07
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Create utils to make it easier to work with custom types
4 participants