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

httproute: add duplicate filter validation #606

Merged
merged 1 commit into from
Apr 16, 2021

Conversation

hbagdi
Copy link
Contributor

@hbagdi hbagdi commented Apr 13, 2021

A variation of this patch first appeared in #506.
This patch is derived from #506 and has been reworked to include it in
the validation package.

What type of PR is this?

/kind feature
What this PR does / why we need it:
Introduces validation for HTTPRoute resource.
This is part of a patch series to get #506 merged in incrementally.

Which issue(s) this PR fixes:

None

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 13, 2021
@k8s-ci-robot k8s-ci-robot requested review from bowei and danehans April 13, 2021 00:36
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 13, 2021
@hbagdi hbagdi force-pushed the feat/filter-validation branch from 5050c35 to d3a5b86 Compare April 13, 2021 00:38
@hbagdi
Copy link
Contributor Author

hbagdi commented Apr 13, 2021

/cc @danehans @cmluciano

@k8s-ci-robot k8s-ci-robot requested a review from cmluciano April 13, 2021 00:38
@hbagdi hbagdi force-pushed the feat/filter-validation branch from d3a5b86 to 31afff7 Compare April 13, 2021 00:56
@hbagdi
Copy link
Contributor Author

hbagdi commented Apr 13, 2021

/cc @bowei @robscott

@k8s-ci-robot k8s-ci-robot requested a review from robscott April 13, 2021 14:31
@hbagdi hbagdi force-pushed the feat/filter-validation branch from 31afff7 to 4de2daf Compare April 13, 2021 14:59
Copy link
Contributor

@stevesloka stevesloka left a comment

Choose a reason for hiding this comment

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

Just a few small nits, otherwise looks good to me @hbagdi!

for _, filter := range rule.Filters {
counts[filter.Type]++
}
// customer filters don't have any validation
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/customer/custom

},
Filters: []gatewayv1a1.HTTPRouteFilter{
{
Type: "RequestMirror",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe use the const type here and for all the other filter types?: HTTPRouteFilterRequestMirror

@hbagdi hbagdi force-pushed the feat/filter-validation branch from 4de2daf to 0d49bd9 Compare April 14, 2021 19:28
@hbagdi
Copy link
Contributor Author

hbagdi commented Apr 14, 2021

@stevesloka I've addressed your comments in the latest commit.

@hbagdi hbagdi added this to the v0.3.0 milestone Apr 14, 2021
Copy link
Contributor

@stevesloka stevesloka left a comment

Choose a reason for hiding this comment

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

lgtm!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hbagdi, stevesloka

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

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 for the work on this! Mostly LGTM, just a few tiny nits.

return validateHTTPRouteSpec(&route.Spec, field.NewPath("spec"))
}

// validateHTTPRouteSpec validates whether required fields of spec are set according to the
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
// validateHTTPRouteSpec validates whether required fields of spec are set according to the
// validateHTTPRouteSpec validates that required fields of spec are set according to the

@@ -75,3 +75,40 @@ func validateListenerHostname(listeners []gatewayv1a1.Listener, path *field.Path
}
return errs
}

// ValidateHTTPRoute validates route according to the Gateway API specification.
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
// ValidateHTTPRoute validates route according to the Gateway API specification.
// ValidateHTTPRoute validates HTTPRoute according to the Gateway API specification.

counts[filter.Type]++
}
// custom filters don't have any validation
counts[gatewayv1a1.HTTPRouteFilterExtensionRef] = 0
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 it might be better to have a specific list of filters that can or can't be repeated. Maybe declare a variable at the top of this file that lists the kinds of filters that can be repeated? Something similar to the upstream networking validation.

Comment on lines 417 to 424
func stringPtr(s string) *string {
return &s
}

func int32Ptr(i int) *int32 {
result := int32(i)
return &result
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we want to add a dependency here, but this is largely similar to https://github.com/kubernetes/utils/tree/master/pointer.


// ValidateHTTPRoute validates route according to the Gateway API specification.
// For additional details of the HTTPRoute spec, refer to:
// https://gateway-api.sigs.k8s.io/spec/#networking.x-k8s.io/v1alpha1.HTTPRoute
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
// https://gateway-api.sigs.k8s.io/spec/#networking.x-k8s.io/v1alpha1.HTTPRoute
// https://gateway-api.sigs.k8s.io/spec/#networking.x-k8s.io/v1alpha1.HTTPRoute

A variation of this patch first appeared in kubernetes-sigs#506.
This patch is derived from kubernetes-sigs#506 and has been reworked to include it in
the validation package.

Co-authored-by: Christopher M. Luciano <cmluciano@isovalent.com>
@hbagdi hbagdi force-pushed the feat/filter-validation branch from 0d49bd9 to 977527f Compare April 16, 2021 14:17
@hbagdi
Copy link
Contributor Author

hbagdi commented Apr 16, 2021

@robscott I've address all of your comments. PTAL.

@robscott
Copy link
Member

Thanks!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 16, 2021
@k8s-ci-robot k8s-ci-robot merged commit 71f9311 into kubernetes-sigs:master Apr 16, 2021
@hbagdi hbagdi deleted the feat/filter-validation branch April 17, 2021 01:39
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/feature Categorizes issue or PR as related to a new feature. 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
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants