From 34f00f8f8976aadedf033af872a208ede2e63487 Mon Sep 17 00:00:00 2001 From: Rob Scott Date: Thu, 15 Dec 2022 07:00:09 +0000 Subject: [PATCH] Cleanup from PR feedback --- apis/v1alpha2/validation/grpcroute.go | 8 ++++---- apis/v1beta1/validation/httproute.go | 10 +++++----- .../v1alpha2/grpcroute/invalid-method.yaml | 2 +- .../v1alpha2/grpcroute/invalid-service.yaml | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 hack/invalid-examples/v1alpha2/grpcroute/invalid-service.yaml diff --git a/apis/v1alpha2/validation/grpcroute.go b/apis/v1alpha2/validation/grpcroute.go index 938794e9e4..74709b8de9 100644 --- a/apis/v1alpha2/validation/grpcroute.go +++ b/apis/v1alpha2/validation/grpcroute.go @@ -184,14 +184,14 @@ func validateGRPCHeaderModifier(filter gatewayv1a2.HTTPHeaderFilter, path *field singleAction[strings.ToLower(string(action.Name))] = true } } - for i, action := range filter.Remove { - if needsErr, ok := singleAction[strings.ToLower(action)]; ok { + for i, name := range filter.Remove { + if needsErr, ok := singleAction[strings.ToLower(name)]; ok { if needsErr { errs = append(errs, field.Invalid(path.Child("remove"), filter.Remove[i], "cannot specify multiple actions for header")) } - singleAction[strings.ToLower(action)] = false + singleAction[strings.ToLower(name)] = false } else { - singleAction[strings.ToLower(action)] = true + singleAction[strings.ToLower(name)] = true } } return errs diff --git a/apis/v1beta1/validation/httproute.go b/apis/v1beta1/validation/httproute.go index dab7b259d5..bdda2889ec 100644 --- a/apis/v1beta1/validation/httproute.go +++ b/apis/v1beta1/validation/httproute.go @@ -176,7 +176,7 @@ func validateHTTPPathMatch(path *gatewayv1b1.HTTPPathMatch, fldPath *field.Path) r, err := regexp.Compile(validPathCharacters) if err != nil { allErrs = append(allErrs, field.InternalError(fldPath.Child("value"), - fmt.Errorf("could not compile path matching regex: %s", err))) + fmt.Errorf("could not compile path matching regex: %w", err))) } else if !r.MatchString(*path.Value) { allErrs = append(allErrs, field.Invalid(fldPath.Child("value"), *path.Value, fmt.Sprintf("must only contain valid characters (matching %s)", validPathCharacters))) @@ -321,14 +321,14 @@ func validateHTTPHeaderModifier(filter gatewayv1b1.HTTPHeaderFilter, path *field singleAction[strings.ToLower(string(action.Name))] = true } } - for i, action := range filter.Remove { - if needsErr, ok := singleAction[strings.ToLower(action)]; ok { + for i, name := range filter.Remove { + if needsErr, ok := singleAction[strings.ToLower(name)]; ok { if needsErr { errs = append(errs, field.Invalid(path.Child("remove"), filter.Remove[i], "cannot specify multiple actions for header")) } - singleAction[strings.ToLower(action)] = false + singleAction[strings.ToLower(name)] = false } else { - singleAction[strings.ToLower(action)] = true + singleAction[strings.ToLower(name)] = true } } return errs diff --git a/hack/invalid-examples/v1alpha2/grpcroute/invalid-method.yaml b/hack/invalid-examples/v1alpha2/grpcroute/invalid-method.yaml index c0a3066817..663d8fb4fa 100644 --- a/hack/invalid-examples/v1alpha2/grpcroute/invalid-method.yaml +++ b/hack/invalid-examples/v1alpha2/grpcroute/invalid-method.yaml @@ -10,7 +10,7 @@ spec: rules: - matches: - method: - - path: ../ + - method: ../ backendRefs: - name: bar-svc port: 50051 diff --git a/hack/invalid-examples/v1alpha2/grpcroute/invalid-service.yaml b/hack/invalid-examples/v1alpha2/grpcroute/invalid-service.yaml new file mode 100644 index 0000000000..b0513c8b26 --- /dev/null +++ b/hack/invalid-examples/v1alpha2/grpcroute/invalid-service.yaml @@ -0,0 +1,16 @@ +apiVersion: gateway.networking.k8s.io/v1alpha2 +kind: GRPCRoute +metadata: + name: invalid-method +spec: + parentRefs: + - name: example-gateway + hostnames: + - "bar.example.com" + rules: + - matches: + - method: + - service: ../ + backendRefs: + - name: bar-svc + port: 50051