kubeshop / kusk-gateway

Kusk-gateway is an OpenAPI-driven API Gateway for Kubernetes
https://kubeshop.github.io/kusk-gateway/
MIT License
253 stars 21 forks source link

Added policy for weighted clusters #1017

Closed jasmingacic closed 1 year ago

jasmingacic commented 1 year ago

Signed-off-by: jasmingacic jasmin.gacic@gmail.com

This PR introduces option for traffic splitting. This PR loosely handles some of the requested features mentioned in https://github.com/kubeshop/kusk-gateway/issues/879

Extended x-kusk policies with upstreams (plural) which is mutually exclusive with upstream

    x-kusk:
      upstreams:
      - service:
          name: httpbin1
          namespace: default
          port: 8080
          weight: 50
      - service:
          name: httpbin2
          namespace: default
          port: 8080
          weight: 50

This translates that traffic will be split between two upstreams by 50% https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/traffic_splitting (please help me understand if I missed anything)

Also one unknown is runtime_key_prefix and header_name. I would appreciate any help I can get with this. https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#config-route-v3-weightedcluster

The example above will result in following envoy config:

 "routes": [
         {
          "match": {
           "path": "/hello",
           "headers": [
            {
             "name": ":method",
             "string_match": {
              "safe_regex": {
               "google_re2": {},
               "regex": "^GET$|^OPTIONS$"
              }
             }
            }
           ]
          },
          "route": {
           "weighted_clusters": {
            "clusters": [
             {
              "name": "httpbin1.default.svc.cluster.local.-8080",
              "weight": 50
             },
             {
              "name": "httpbin2.default.svc.cluster.local.-8080",
              "weight": 50
             }
            ]
           },
....
 {
          "match": {
           "path": "/validated",
           "headers": [
            {
             "name": ":method",
             "string_match": {
              "safe_regex": {
               "google_re2": {},
               "regex": "^POST$|^OPTIONS$"
              }
             }
            }
           ]
          },
          "route": {
           "weighted_clusters": {
            "clusters": [
             {
              "name": "httpbin1.default.svc.cluster.local.-8080",
              "weight": 50
             },
             {
              "name": "httpbin2.default.svc.cluster.local.-8080",
              "weight": 50
             }
            ]
           },
netlify[bot] commented 1 year ago

Deploy Preview for kusk-docs-preview canceled.

Name Link
Latest commit e0cf658d4f33d9feb4b7f24fca5de19e45c1d19d
Latest deploy log https://app.netlify.com/sites/kusk-docs-preview/deploys/639311452d4b3c0008b23e73
aabedraba commented 1 year ago

Maybe we could add guard rails for users so the sum of the weights is always 100?

jasmingacic commented 1 year ago

Had to disable check-basic for some reason it was not passing. Anyways I consider the test redundant as we are already setting up and tearing down API, Fleets and Staticroutes.