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

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

Closed
rsaelim opened this issue Feb 27, 2024 · 9 comments
Assignees
Milestone

Comments

@rsaelim
Copy link

rsaelim commented Feb 27, 2024

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 rsaelim added the triage label Feb 27, 2024
@arkodg
Copy link
Contributor

arkodg commented Feb 27, 2024

@rsaelim can you share your use case ?

@rsaelim
Copy link
Author

rsaelim commented Feb 28, 2024

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

@arkodg
Copy link
Contributor

arkodg commented Feb 28, 2024

raised kubernetes-sigs/gateway-api#2826 in upstream

@davidalger
Copy link
Contributor

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

Copy link

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

@github-actions github-actions bot added the stale label Mar 31, 2024
@Demacr
Copy link

Demacr commented Jul 10, 2024

Bump

Copy link

github-actions bot commented Aug 9, 2024

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

@arkodg
Copy link
Contributor

arkodg commented Sep 19, 2024

we can reuse the same structure of body from #1400 when adding this into the HTTPRouteFilter

arkodg added a commit to arkodg/gateway that referenced this issue Sep 26, 2024
Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>
arkodg added a commit to arkodg/gateway that referenced this issue Oct 16, 2024
Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>
@arkodg arkodg removed the help wanted Extra attention is needed label Oct 18, 2024
@arkodg arkodg self-assigned this Oct 18, 2024
arkodg added a commit that referenced this issue Oct 18, 2024
* api: direct response

Relates to #2714

Signed-off-by: Arko Dasgupta <[email protected]>
arkodg added a commit to arkodg/gateway that referenced this issue Oct 24, 2024
Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>
zirain pushed a commit that referenced this issue Oct 24, 2024
* feat: direct response

Relates to #2714

Signed-off-by: Arko Dasgupta <[email protected]>

* provider logic

Signed-off-by: Arko Dasgupta <[email protected]>

* default status code is 200

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
rudrakhp pushed a commit to rudrakhp/gateway that referenced this issue Oct 24, 2024
* feat: direct response

Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>

* provider logic

Signed-off-by: Arko Dasgupta <[email protected]>

* default status code is 200

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
rudrakhp pushed a commit to rudrakhp/gateway that referenced this issue Oct 24, 2024
* feat: direct response

Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>

* provider logic

Signed-off-by: Arko Dasgupta <[email protected]>

* default status code is 200

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
rudrakhp pushed a commit to rudrakhp/gateway that referenced this issue Oct 24, 2024
* feat: direct response

Relates to envoyproxy#2714

Signed-off-by: Arko Dasgupta <[email protected]>

* provider logic

Signed-off-by: Arko Dasgupta <[email protected]>

* default status code is 200

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
@arkodg arkodg modified the milestones: v1.2.0-rc1, v1.2.0 Oct 24, 2024
@arkodg
Copy link
Contributor

arkodg commented Oct 24, 2024

closing this one since we have a separate issue for docs and e2e #4511

@arkodg arkodg closed this as completed Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants