gateway icon indicating copy to clipboard operation
gateway copied to clipboard

Feature Request: Add support for configuring gateway to direct_response on HTTP routes.

Open rsaelim opened this issue 1 year ago • 8 comments

Description:

It would be nice to support use case where users can configure the gateway to direct respond 200 on a HTTP route without upstream backend.

rsaelim avatar Feb 27 '24 20:02 rsaelim

@rsaelim can you share your use case ?

arkodg avatar Feb 27 '24 21:02 arkodg

My use case: I want to configure the gateway to respond to requests matching on certain http route rule with no upstream backend, and just return a 200.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: httpRoutes
  namespace: envoy-gateway-system
spec:
  hostnames:
  - "api.example.com"
  parentRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: envoy-gateway
    namespace: envoy-gateway-system
  rules:
  - matches:
    - path:
        type: Exact
        value: /ok # I want the gateway to directly respond to requests matching this route path with a 200.
  - matches:
    - path:
        type: Exact
        value: /user
     backendRefs:
    - group: ""
      kind: service
      name: user-service-http
      port: 3000

rsaelim avatar Feb 28 '24 14:02 rsaelim

raised https://github.com/kubernetes-sigs/gateway-api/issues/2826 in upstream

arkodg avatar Feb 28 '24 15:02 arkodg

You can sorta do this with a fault injection policy:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: fault-injection-200
spec:
  parentRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: eg
  rules:
  - backendRefs:
    - kind: Service
      name: backend
      port: 3000
    matches:
    - path:
        type: PathPrefix
        value: /fault-injection-200
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
  name: fault-injection-200
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: fault-injection-200
  faultInjection:
    abort:
      httpStatus: 200

The result:

$ curl -sv 172.18.255.200/fault-injection-200/
*   Trying 172.18.255.200:80...
* Connected to 172.18.255.200 (172.18.255.200) port 80
> GET /fault-injection-200/ HTTP/1.1
> Host: 172.18.255.200
> User-Agent: curl/8.4.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-length: 18
< content-type: text/plain
< date: Thu, 29 Feb 2024 21:32:05 GMT
< 
* Connection #0 to host 172.18.255.200 left intact
fault filter abort

If all you're using the 200 fault responses for is a synthetic 'ok' response, it is also possible to override the fault filter abort text for just the 200 fault responses using a local reply config:

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyPatchPolicy
metadata:
  name: fault-injection-200
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: eg
  type: JSONPatch
  jsonPatches:
  - type: type.googleapis.com/envoy.config.listener.v3.Listener
    name: default/eg/http
    operation:
      op: add
      path: /default_filter_chain/filters/0/typed_config/local_reply_config
      value:
        mappers:
        - body:
            inline_string: OK
          filter:
            status_code_filter:
              comparison:
                op: EQ
                value:
                  default_value: "200"
                  runtime_key: key_b

davidalger avatar Feb 29 '24 21:02 davidalger

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

github-actions[bot] avatar Mar 31 '24 00:03 github-actions[bot]

Bump

Demacr avatar Jul 10 '24 12:07 Demacr

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

github-actions[bot] avatar Aug 09 '24 20:08 github-actions[bot]