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

Using PolicyTargetReference instead of Selector #612

Merged
merged 2 commits into from
May 13, 2024

Conversation

didierofrivia
Copy link
Collaborator

@didierofrivia didierofrivia commented May 3, 2024

In order to not rely on Gateway a̶n̶n̶o̶t̶a̶t̶i̶o̶n̶s̶ labels/selectors, we are now using PolicyTargetReference. This fixes the issue when no annotation has been added to the managed gateway (or removed/updated).

Verification steps

  1. Set up the cluster
make local-setup
  1. Remove the deployed gw label
kubectl -n istio-system label gateway istio-ingressgateway istio-
  1. Apply Kuadrant CR
kubectl -n kuadrant-system apply -f - <<EOF
apiVersion: kuadrant.io/v1beta1
kind: Kuadrant
metadata:
  name: kuadrant
spec: {}
EOF
  1. Deploy ToyStore API and route the traffic
kubectl apply -f examples/toystore/toystore.yaml

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: toystore
spec:
  parentRefs:
  - name: istio-ingressgateway
    namespace: istio-system
  hostnames:
  - api.toystore.com
  rules:
  - matches:
    - path:
        type: Exact
        value: "/toy"
      method: GET
    backendRefs:
    - name: toystore
      port: 80
EOF
  1. Apply a RLP
kubectl apply -f - <<EOF
apiVersion: kuadrant.io/v1beta2
kind: RateLimitPolicy
metadata:
  name: toystore
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: toystore
  limits:
    "default":
      rates:
      - limit: 5
        duration: 10
        unit: second
EOF
  1. Check the envoy config for the wasm shim configuration for the RLP
kubectl port-forward --namespace istio-system deployment/istio-ingressgateway-istio 15000:15000 &

curl -v "<http://127.0.0.1:15000/config_dump?format=json>" | yq e -P -

It should contain

...
 config:
              name: istio-system.kuadrant-istio-ingressgateway
              vm_config:
                runtime: envoy.wasm.runtime.v8
                code:
                  local:
                    filename: /var/lib/istio/data/81221938ebcbc4550eb35f72aac65d0939d89335832b5a022226fb2526806e9e/9b28356942b98c2a73dd1428403ec45836f956114208dfceb88f8f957e94e45d.wasm
              configuration:
                '@type': type.googleapis.com/google.protobuf.StringValue
                value: '{"failureMode":"deny","rateLimitPolicies":[{"domain":"default/toystore","hostnames":["api.toystore.com"],"name":"default/toystore","rules":[{"conditions":[{"allOf":[{"operator":"eq","selector":"request.url_path","value":"/toy"},{"operator":"eq","selector":"request.method","value":"GET"}]}],"data":[{"static":{"key":"limit.default__37a8eec1","value":"1"}}]}],"service":"kuadrant-rate-limiting-service"}]}'
...

Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.54%. Comparing base (ece13e8) to head (cfd9dde).
Report is 87 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
+ Coverage   80.20%   82.54%   +2.33%     
==========================================
  Files          64       72       +8     
  Lines        4492     5415     +923     
==========================================
+ Hits         3603     4470     +867     
- Misses        600      639      +39     
- Partials      289      306      +17     
Flag Coverage Δ
integration 74.08% <100.00%> (+2.80%) ⬆️
unit 33.73% <83.33%> (+3.70%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
api/v1beta1 (u) 71.42% <ø> (ø)
api/v1beta2 (u) 93.58% <100.00%> (+2.16%) ⬆️
pkg/common (u) 83.78% <ø> (-5.05%) ⬇️
pkg/istio (u) 75.86% <ø> (+1.94%) ⬆️
pkg/log (u) 100.00% <ø> (+5.26%) ⬆️
pkg/reconcilers (u) ∅ <ø> (∅)
pkg/rlptools (u) 79.84% <ø> (+0.39%) ⬆️
controllers (i) 80.81% <84.03%> (+4.00%) ⬆️
Files Coverage Δ
controllers/rate_limiting_wasmplugin_controller.go 80.69% <100.00%> (ø)
pkg/istio/utils.go 100.00% <100.00%> (ø)

... and 33 files with indirect coverage changes

@didierofrivia didierofrivia marked this pull request as ready for review May 10, 2024 10:18
@didierofrivia didierofrivia requested a review from a team as a code owner May 10, 2024 10:18
@ehearneRedHat ehearneRedHat self-requested a review May 10, 2024 13:12
Copy link
Contributor

@ehearneRedHat ehearneRedHat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge - request did contain

config:
              name: istio-system.kuadrant-istio-ingressgateway
              vm_config:
                runtime: envoy.wasm.runtime.v8
                code:
                  local:
                    filename: /var/lib/istio/data/81221938ebcbc4550eb35f72aac65d0939d89335832b5a022226fb2526806e9e/9b28356942b98c2a73dd1428403ec45836f956114208dfceb88f8f957e94e45d.wasm
              configuration:
                '@type': type.googleapis.com/google.protobuf.StringValue
                value: '{"failureMode":"deny","rateLimitPolicies":[{"domain":"default/toystore","hostnames":["api.toystore.com"],"name":"default/toystore","rules":[{"conditions":[{"allOf":[{"operator":"eq","selector":"request.url_path","value":"/toy"},{"operator":"eq","selector":"request.method","value":"GET"}]}],"data":[{"static":{"key":"limit.default__37a8eec1","value":"1"}}]}],"service":"kuadrant-rate-limiting-service"}]}'

pkg/istio/utils.go Outdated Show resolved Hide resolved
@guicassolato
Copy link
Contributor

What does this have to do with gateway annotations?

@eguzki
Copy link
Contributor

eguzki commented May 13, 2024

What does this have to do with gateway annotations?

When the gateway does not have labels (nothing to do with annotations), the label selector implemented by kuadrant is failing as it is empty. Empty label selector will not match any gateway, thus rate limiting not enforced.

@guicassolato
Copy link
Contributor

What does this have to do with gateway annotations?

When the gateway does not have labels (nothing to do with annotations), the label selector implemented by kuadrant is failing as it is empty. Empty label selector will not match any gateway, thus rate limiting not enforced.

Thanks @eguzki. That's what I figured. Maybe fix in the description of the PR, @didierofrivia?

@didierofrivia didierofrivia merged commit 5f72dcf into main May 13, 2024
22 checks passed
@didierofrivia didierofrivia deleted the policy-targetref-wasm branch May 13, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants