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

Refactoring path modifier to use union discriminator #1124

Merged
merged 1 commit into from
May 19, 2022

Conversation

robscott
Copy link
Member

@robscott robscott commented Apr 21, 2022

What type of PR is this?
/kind cleanup
/kind api-change

What this PR does / why we need it:
This is a follow up to @thockin's feedback in #1086 (comment). It makes the following changes:

  • HTTPPathModifier API
    • Replaces "Substitution" with new type-specific "ReplaceFullPath" and "ReplacePrefixMatch" fields
    • Renames "Absolute" to "ReplaceFullPath" for more consistency
  • Validation
    • Adds webhook validation to ensure that only type-appropriate fields are set in HTTPPathModifier (this could be done with oneOf validation, but that is not supported with Kubebuilder annotations: Support more complex validations (oneOf/anyOf/allOf/etc) controller-tools#461)
    • Adds webhook validation to ensure that rewrite and redirect validation
    • Adds examples of path rewrites and redirects that will be used in verification script
  • Use "PreciseHostname" instead of "Hostname" URLRewrite filter

Does this PR introduce a user-facing change?:
Not sure this needs a release note because none of the updated fields were ever released, so up to author of changelog as far as if this should be included:

- HTTPPathModifier API
  - Replaces "Substitution" with new type-specific "ReplaceFullPath" and "ReplacePrefixMatch" fields
  - Renames "Absolute" to "ReplaceFullPath" for more consistency
- Validation
  - Adds webhook validation to ensure that only type-appropriate fields are set in HTTPPathModifier (this could be done with oneOf validation, but that is not supported with Kubebuilder annotations: https://github.com/kubernetes-sigs/controller-tools/issues/461)
  - Adds webhook validation to ensure that rewrite and redirect validation 
  - Adds examples of path rewrites and redirects that will be used in verification script
- Use "PreciseHostname" instead of "Hostname" URLRewrite filter

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Apr 21, 2022
@robscott robscott added this to the v1beta1 milestone Apr 21, 2022
@robscott
Copy link
Member Author

This is a relatively large change, adding a hold until we can get some broader consensus.

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 21, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: robscott

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 requested review from bowei and hbagdi April 21, 2022 16:19
@k8s-ci-robot k8s-ci-robot added 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. labels Apr 21, 2022
@robscott robscott force-pushed the rewrite-cleanup branch 2 times, most recently from a58e11a to a274447 Compare April 21, 2022 17:07
@robscott
Copy link
Member Author

There's a kubernetes-api-reviewers thread that's relevant to this PR.

@@ -705,17 +705,25 @@ type HTTPPathModifier struct {
// Type defines the type of path modifier.
//
// <gateway:experimental>
// +kubebuilder:validation:Enum=Absolute;ReplacePrefixMatch
// +kubebuilder:validation:Enum=ReplaceFullPath;ReplacePrefixMatch
Copy link

Choose a reason for hiding this comment

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

Since you really don't have any other fields than union members in that struct, I don't think the discriminator is useful at all.

Choose a reason for hiding this comment

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

^ this was me, I posted with a temporary account ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this adds room for growth. The goal here is to add additional types in the future. Since we already have 14 implementations and integrations, and have more on the way, it's very likely that at least some of these will trail the version of the API deployed in the cluster. A discriminator field allows those implementations to communicate that they don't support a specific type, instead of just seeing an empty struct and not knowing what to do with it.

Choose a reason for hiding this comment

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

Yeah, they don't get a lot more value from seeing the struct empty vs seeing the discrimator set to a value that doesn't make sense (but they get a little value). In both cases, they can manually clear everything/set the discriminator to the right value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I chatted with @thockin about this, and while I think he still has significant reservations about using a union discriminator, I think he's on board with starting with one. The idea is that it's impossible to retroactively add a discriminator, but we could always make a discriminator optional and/or provide a smart default in the future. (Please correct me if I misunderstood anything).

Copy link
Contributor

@youngnick youngnick left a comment

Choose a reason for hiding this comment

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

LGTM with one caveat about the kubebuilder enum.

apis/v1alpha2/httproute_types.go Show resolved Hide resolved
@robscott
Copy link
Member Author

Discussed at community meeting today. Seems like there's consensus with this approach. I've pushed an update to address feedback and going to go ahead and remove the hold so we can get this in with the next LGTM.

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 10, 2022
@youngnick
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 19, 2022
@k8s-ci-robot k8s-ci-robot merged commit ffe1dd0 into kubernetes-sigs:master May 19, 2022
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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

5 participants