From 5d08c17683676781f14cfe7f55698cfee8d82c16 Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Thu, 30 Jan 2025 13:34:38 -0800 Subject: [PATCH] more validations Signed-off-by: Arko Dasgupta --- internal/gatewayapi/clustersettings.go | 14 ++- .../backendtrafficpolicy-with-retries.in.yaml | 34 +++++++ ...backendtrafficpolicy-with-retries.out.yaml | 93 ++++++++++++++++++- 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/internal/gatewayapi/clustersettings.go b/internal/gatewayapi/clustersettings.go index 1c4d3b8ba08..76d3e1aeaff 100644 --- a/internal/gatewayapi/clustersettings.go +++ b/internal/gatewayapi/clustersettings.go @@ -521,16 +521,22 @@ func buildRetry(r *egv1a1.Retry) (*ir.Retry, error) { if r.PerRetry.BackOff != nil { if r.PerRetry.BackOff.MaxInterval != nil || r.PerRetry.BackOff.BaseInterval != nil { bop := &ir.BackOffPolicy{} - if r.PerRetry.BackOff.MaxInterval != nil { - bop.MaxInterval = r.PerRetry.BackOff.MaxInterval - } - if r.PerRetry.BackOff.BaseInterval != nil { bop.BaseInterval = r.PerRetry.BackOff.BaseInterval if bop.BaseInterval.Duration == 0 { return nil, fmt.Errorf("baseInterval cannot be set to 0s") } } + if r.PerRetry.BackOff.MaxInterval != nil { + bop.MaxInterval = r.PerRetry.BackOff.MaxInterval + if bop.MaxInterval.Duration == 0 { + return nil, fmt.Errorf("maxInterval cannot be set to 0s") + } + if bop.BaseInterval != nil && bop.BaseInterval.Duration > bop.MaxInterval.Duration { + return nil, fmt.Errorf("maxInterval cannot be less than baseInterval") + } + } + pr.BackOff = bop bpr = true } diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.in.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.in.yaml index 51ba1b8e49c..bf2e264bf27 100644 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.in.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.in.yaml @@ -81,6 +81,25 @@ httpRoutes: backendRefs: - name: service-1 port: 8080 +- apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + metadata: + namespace: default + name: httproute-3 + spec: + hostnames: + - gateway.envoyproxy.io + parentRefs: + - namespace: envoy-gateway + name: gateway-2 + sectionName: http + rules: + - matches: + - path: + value: "/route3" + backendRefs: + - name: service-1 + port: 8080 backendTrafficPolicies: - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy @@ -139,3 +158,18 @@ backendTrafficPolicies: perRetry: backoff: baseInterval: 0s +- apiVersion: gateway.envoyproxy.io/v1alpha1 + kind: BackendTrafficPolicy + metadata: + namespace: default + name: policy-for-route-3 + spec: + targetRef: + group: gateway.networking.k8s.io + kind: HTTPRoute + name: httproute-3 + retry: + perRetry: + backoff: + baseInterval: 2s + maxInterval: 1s diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.out.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.out.yaml index 1f18b56a2f1..2e3dd5bbbfc 100644 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.out.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-retries.out.yaml @@ -69,6 +69,37 @@ backendTrafficPolicies: status: "False" type: Accepted controllerName: gateway.envoyproxy.io/gatewayclass-controller +- apiVersion: gateway.envoyproxy.io/v1alpha1 + kind: BackendTrafficPolicy + metadata: + creationTimestamp: null + name: policy-for-route-3 + namespace: default + spec: + retry: + perRetry: + backOff: + baseInterval: 2s + maxInterval: 1s + targetRef: + group: gateway.networking.k8s.io + kind: HTTPRoute + name: httproute-3 + status: + ancestors: + - ancestorRef: + group: gateway.networking.k8s.io + kind: Gateway + name: gateway-2 + namespace: envoy-gateway + sectionName: http + conditions: + - lastTransitionTime: null + message: 'Retry: maxInterval cannot be less than baseInterval.' + reason: Invalid + status: "False" + type: Accepted + controllerName: gateway.envoyproxy.io/gatewayclass-controller - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy metadata: @@ -161,7 +192,7 @@ gateways: protocol: HTTP status: listeners: - - attachedRoutes: 2 + - attachedRoutes: 3 conditions: - lastTransitionTime: null message: Sending translated listener configuration to the data plane @@ -295,6 +326,44 @@ httpRoutes: name: gateway-2 namespace: envoy-gateway sectionName: http +- apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + metadata: + creationTimestamp: null + name: httproute-3 + namespace: default + spec: + hostnames: + - gateway.envoyproxy.io + parentRefs: + - name: gateway-2 + namespace: envoy-gateway + sectionName: http + rules: + - backendRefs: + - name: service-1 + port: 8080 + matches: + - path: + value: /route3 + status: + parents: + - conditions: + - lastTransitionTime: null + message: Route is accepted + reason: Accepted + status: "True" + type: Accepted + - lastTransitionTime: null + message: Resolved all the Object references for the Route + reason: ResolvedRefs + status: "True" + type: ResolvedRefs + controllerName: gateway.envoyproxy.io/gatewayclass-controller + parentRef: + name: gateway-2 + namespace: envoy-gateway + sectionName: http infraIR: envoy-gateway/gateway-1: proxy: @@ -415,6 +484,28 @@ xdsIR: distinct: false name: "" prefix: /route2 + - destination: + name: httproute/default/httproute-3/rule/0 + settings: + - addressType: IP + endpoints: + - host: 7.7.7.7 + port: 8080 + protocol: HTTP + weight: 1 + directResponse: + statusCode: 500 + hostname: gateway.envoyproxy.io + isHTTP2: false + metadata: + kind: HTTPRoute + name: httproute-3 + namespace: default + name: httproute/default/httproute-3/rule/0/match/0/gateway_envoyproxy_io + pathMatch: + distinct: false + name: "" + prefix: /route3 - destination: name: httproute/default/httproute-1/rule/0 settings: