Skip to content

Use generics for Gateway API pointer helpers#4905

Merged
sunjayBhatia merged 4 commits intoprojectcontour:dev-gwapi-0.6from
sunjayBhatia:use-generics-gateway-helpers
Dec 13, 2022
Merged

Use generics for Gateway API pointer helpers#4905
sunjayBhatia merged 4 commits intoprojectcontour:dev-gwapi-0.6from
sunjayBhatia:use-generics-gateway-helpers

Conversation

@sunjayBhatia
Copy link
Copy Markdown
Member

The internal/gatewayapi package has a lot of helper functions to get pointers to Gateway API types that are based on primitives.

We can use a generic helper function to implement this instead:

func To[T any](v T) *T {
       return &v
}

e.g. ref.To(<some primitive value>)

This came from the fact that Gateway API 0.6.0 review is considering removing the helpers added to the API, see: https://github.com/kubernetes-sigs/gateway-api/pull/1538/files/a5c0a509d597cc9a99e91f4629257105ad536877#r1026842150

We never started using them, but we can just get rid of the code we had in favor of a generics approach

The first commit shows a smaller example set of removals, the second finishes it up

Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@sunjayBhatia sunjayBhatia added the release-note/none-required Marks a PR as not requiring a release note. Should only be used for very small changes. label Dec 6, 2022
@sunjayBhatia sunjayBhatia requested a review from a team as a code owner December 6, 2022 21:45
@sunjayBhatia sunjayBhatia requested review from skriss and tsaarni and removed request for a team December 6, 2022 21:45
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 6, 2022

Codecov Report

Merging #4905 (1669ad1) into dev-gwapi-0.6 (2260371) will decrease coverage by 0.07%.
The diff coverage is 96.29%.

❗ Current head 1669ad1 differs from pull request most recent head 11dce07. Consider uploading reports for the commit 11dce07 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           dev-gwapi-0.6    #4905      +/-   ##
=================================================
- Coverage          76.35%   76.28%   -0.08%     
=================================================
  Files                139      140       +1     
  Lines              16680    16642      -38     
=================================================
- Hits               12736    12695      -41     
- Misses              3693     3696       +3     
  Partials             251      251              
Impacted Files Coverage Δ
internal/gatewayapi/helpers.go 84.54% <94.44%> (-4.13%) ⬇️
internal/dag/gatewayapi_processor.go 96.61% <100.00%> (ø)
internal/k8s/statusaddress.go 80.11% <100.00%> (ø)
internal/ref/ref.go 100.00% <100.00%> (ø)
internal/status/gatewaystatus.go 72.93% <100.00%> (ø)
internal/sorter/sorter.go 97.44% <0.00%> (-1.54%) ⬇️

Copy link
Copy Markdown
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

One nit, otherwise LGTM, nice cleanup! As discussed, after this goes in we can also look to get rid of our dependency on k8s.io/utils/pointer.

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@sunjayBhatia sunjayBhatia merged commit c2d2722 into projectcontour:dev-gwapi-0.6 Dec 13, 2022
@sunjayBhatia sunjayBhatia deleted the use-generics-gateway-helpers branch December 13, 2022 14:07
sunjayBhatia added a commit to sunjayBhatia/contour that referenced this pull request Dec 14, 2022
Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
sunjayBhatia added a commit that referenced this pull request Dec 14, 2022
* drop support for ReferencePolicy (#4830)

Drops support for ReferencePolicy which
has been replaced by ReferenceGrant in
Gateway API.

* update to latest Gateway API commit (#4839)

- Update to v1beta1 ReferenceGrant
- HTTPRequestHeaderFilter -> HTTPHeaderFilter
- GatewayConditionScheduled -> GatewayConditionAccepted
- ListenerConditionDetached -> ListenerConditionAccepted

* updates for SupportedFeatures changes (#4844)

* replace Gateway/Listener Ready conditions with Programmed (#4849)

Replaces the "Ready" condition used for Gateways
and Listeners with "Programmed".

* update to Gateway API v0.6.0-rc1 (#4891)

* Use generics for Gateway API pointer helpers (#4905)

Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Fixes #4555 
Fixes #4699 
Fixes #4848 

Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: Steve Kriss <krisss@vmware.com>
yangyy93 pushed a commit to projectsesame/contour that referenced this pull request Feb 16, 2023
* drop support for ReferencePolicy (projectcontour#4830)

Drops support for ReferencePolicy which
has been replaced by ReferenceGrant in
Gateway API.

* update to latest Gateway API commit (projectcontour#4839)

- Update to v1beta1 ReferenceGrant
- HTTPRequestHeaderFilter -> HTTPHeaderFilter
- GatewayConditionScheduled -> GatewayConditionAccepted
- ListenerConditionDetached -> ListenerConditionAccepted

* updates for SupportedFeatures changes (projectcontour#4844)

* replace Gateway/Listener Ready conditions with Programmed (projectcontour#4849)

Replaces the "Ready" condition used for Gateways
and Listeners with "Programmed".

* update to Gateway API v0.6.0-rc1 (projectcontour#4891)

* Use generics for Gateway API pointer helpers (projectcontour#4905)

Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Fixes projectcontour#4555
Fixes projectcontour#4699
Fixes projectcontour#4848

Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: yy <yang.yang@daocloud.io>
yangyy93 pushed a commit to projectsesame/contour that referenced this pull request Feb 16, 2023
* drop support for ReferencePolicy (projectcontour#4830)

Drops support for ReferencePolicy which
has been replaced by ReferenceGrant in
Gateway API.

* update to latest Gateway API commit (projectcontour#4839)

- Update to v1beta1 ReferenceGrant
- HTTPRequestHeaderFilter -> HTTPHeaderFilter
- GatewayConditionScheduled -> GatewayConditionAccepted
- ListenerConditionDetached -> ListenerConditionAccepted

* updates for SupportedFeatures changes (projectcontour#4844)

* replace Gateway/Listener Ready conditions with Programmed (projectcontour#4849)

Replaces the "Ready" condition used for Gateways
and Listeners with "Programmed".

* update to Gateway API v0.6.0-rc1 (projectcontour#4891)

* Use generics for Gateway API pointer helpers (projectcontour#4905)

Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Fixes projectcontour#4555
Fixes projectcontour#4699
Fixes projectcontour#4848

Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: yy <yang.yang@daocloud.io>
vmw-yingy pushed a commit to vmw-yingy/contour that referenced this pull request Feb 28, 2023
* drop support for ReferencePolicy (projectcontour#4830)

Drops support for ReferencePolicy which
has been replaced by ReferenceGrant in
Gateway API.

* update to latest Gateway API commit (projectcontour#4839)

- Update to v1beta1 ReferenceGrant
- HTTPRequestHeaderFilter -> HTTPHeaderFilter
- GatewayConditionScheduled -> GatewayConditionAccepted
- ListenerConditionDetached -> ListenerConditionAccepted

* updates for SupportedFeatures changes (projectcontour#4844)

* replace Gateway/Listener Ready conditions with Programmed (projectcontour#4849)

Replaces the "Ready" condition used for Gateways
and Listeners with "Programmed".

* update to Gateway API v0.6.0-rc1 (projectcontour#4891)

* Use generics for Gateway API pointer helpers (projectcontour#4905)

Can get rid of our existing gatewayapi package helpers for getting
pointers to gateway api types based on primitive types

Also found some more instances of v1alpha2 package being used where we
should switch to v1beta1

Fixes projectcontour#4555 
Fixes projectcontour#4699 
Fixes projectcontour#4848 

Signed-off-by: Steve Kriss <krisss@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: Steve Kriss <krisss@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/none-required Marks a PR as not requiring a release note. Should only be used for very small changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants