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

Introduces a Validation Package #597

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

danehans
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:
This PR adds a validation package. It's needed so implementors no longer need to create a Gateway API validation package. This approach provides validation consistency across implementations, including the future validating webhook. The package is modeled after the Kubernetes networking APIs validation package.

Which issue(s) this PR fixes:

Partially Fixes # #487

Does this PR introduce a user-facing change?:

NONE

/cc @stevesloka @youngnick @jpeach

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 30, 2021
@k8s-ci-robot
Copy link
Contributor

@danehans: GitHub didn't allow me to request PR reviews from the following users: stevesloka.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

What type of PR is this?

/kind feature

What this PR does / why we need it:
This PR adds a validation package. It's needed so implementors no longer need to create a Gateway API validation package. This approach provides validation consistency across implementations, including the future validating webhook. The package is modeled after the Kubernetes networking APIs validation package.

Which issue(s) this PR fixes:

Partially Fixes # #487

Does this PR introduce a user-facing change?:

NONE

/cc @stevesloka @youngnick @jpeach

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 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. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 30, 2021
.golangci.yml Outdated Show resolved Hide resolved
@hbagdi
Copy link
Contributor

hbagdi commented Mar 30, 2021

We should figure out a way how to integrate this with #506.
/cc @cmluciano

@danehans
Copy link
Contributor Author

We should figure out a way how to integrate this with #506.

@hbagdi that's what I discussed with @robscott and @jpeach in #487. As mentioned in the description, I would expect the webhook implementation to be a consumer of this package. cc: @cmluciano

@danehans
Copy link
Contributor Author

@bowei thanks for the review. Commit 32c1d66 resolves #597 (comment) and #597 (comment).

// - A wildcard DNS subdomain as defined by RFC 1034 (section 4.3.3).
func ValidateListenerHostname(listeners []gatewayv1a1.Listener, path *field.Path) field.ErrorList {
var errs field.ErrorList
for i, h := range listeners {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest early breaks to improve readability:

for i, h := range listeners {
        if h.Hostname == nil {
                continue
        }
        switch *h.Hostname {
        case  "": 
                // is this really valid?
        case "*":
                // valid wildcard
        default:
                // parse and check
        }
} 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored the conditional logic that I think makes it easier to follow.

"k8s.io/apimachinery/pkg/util/validation/field"
)

// ValidateGateway validates Gateway objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we elaborate here and give some indication on what sorts of rules this enforces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I provided a link to the gateway spec and include details in the functions that are validating specific fields.

errs = append(errs, field.Invalid(path.Index(i).Child("hostname"), hostname, "must be a DNS hostname, not an IP address"))
}
if strings.Contains(hostname, "*") {
for _, msg := range validation.IsWildcardDNS1123Subdomain(hostname) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure we can validate this with a regex on the CRD.

@danehans
Copy link
Contributor Author

@jpeach thanks for the review. Commit a8bd76c resolves most of your feedback.

@danehans
Copy link
Contributor Author

danehans commented Apr 1, 2021

As a follow-on from today's community meeting, I did a quick implementation of the validation pkg as a proof-of-concept for #506, PTAL.

@bowei
Copy link
Contributor

bowei commented Apr 7, 2021

Small changes and then this should be able to go in...

@danehans
Copy link
Contributor Author

danehans commented Apr 7, 2021

@bowei thanks again for the review. Commit 30ca87d resolves your #597 (comment).

@bowei
Copy link
Contributor

bowei commented Apr 8, 2021

/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 Apr 8, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bowei, danehans

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 merged commit 0d6be16 into kubernetes-sigs:master Apr 8, 2021
@danehans danehans deleted the valid_pkg branch May 20, 2021 18:45
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
None yet
Development

Successfully merging this pull request may close these issues.

5 participants