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

v1alpha2 validation fix/update #831

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions apis/v1alpha2/validation/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package validation

import (
"fmt"
"net"
"strings"

Expand All @@ -36,8 +37,37 @@ func ValidateGateway(gw *gatewayv1a2.Gateway) field.ErrorList {
// validateGatewaySpec validates whether required fields of spec are set according to the
// Gateway API specification.
func validateGatewaySpec(spec *gatewayv1a2.GatewaySpec, path *field.Path) field.ErrorList {
// TODO [danehans]: Add additional validation of spec fields.
return validateGatewayListeners(spec.Listeners, path.Child("listeners"))
if errList := validateGatewayListeners(spec.Listeners, path.Child("listeners")); len(errList) > 0 {
fmt.Printf("Failed validating gateway listeners.")
return errList
}
ccfishk marked this conversation as resolved.
Show resolved Hide resolved

if errList := validateGatewayClassName(spec.GatewayClassName, path.Child("gatewayClassName")); len(errList) > 0 {
return errList

}

if errList := validateGatewayAddresses(spec.Addresses, path.Child("addresses")); len(errList) > 0 {
return errList
}

return nil
}

func validateGatewayClassName(gwclsName string, path *field.Path) field.ErrorList {
var errs field.ErrorList
if len(gwclsName) == 0 || len(gwclsName) > 253 {
errs = append(errs, field.Invalid(path, gwclsName, "must greater than 1 and less than 253"))
ccfishk marked this conversation as resolved.
Show resolved Hide resolved
}
return errs
}

func validateGatewayAddresses(addresses []gatewayv1a2.GatewayAddress, path *field.Path) field.ErrorList {
var errs field.ErrorList
if len(addresses) > 16 {
errs = append(errs, field.Invalid(path, "addresses length", " maximum is 16 items."))
}
return errs
}

// validateGatewayListeners validates whether required fields of listeners are set according
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha2/validation/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func validateHTTPRouteUniqueFilters(rules []gatewayv1a2.HTTPRouteRule, path *fie
}
// custom filters don't have any validation
for _, key := range repeatableHTTPRouteFilters {
counts[key] = 0
delete(counts, key)
}

for filterType, count := range counts {
Expand Down
3 changes: 1 addition & 2 deletions apis/v1alpha2/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ func TestValidateHTTPRoute(t *testing.T) {
}
for _, tt := range tests {
// copy variable to avoid scope problems with ranges
tt := tt
t.Run(tt.name, func(t *testing.T) {
ccfishk marked this conversation as resolved.
Show resolved Hide resolved
errs := ValidateHTTPRoute(&tt.hRoute)
errs := validateHTTPRouteUniqueFilters(&tt.hRoute.)
ccfishk marked this conversation as resolved.
Show resolved Hide resolved
if len(errs) != tt.errCount {
t.Errorf("ValidateHTTPRoute() got %v errors, want %v errors", len(errs), tt.errCount)
}
Expand Down