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

RLP Defaults #456

Merged
merged 12 commits into from
Apr 10, 2024
Merged

RLP Defaults #456

merged 12 commits into from
Apr 10, 2024

Conversation

KevFan
Copy link
Contributor

@KevFan KevFan commented Mar 11, 2024

Description

Closes: #455

  • Adds defaults field for full atomic explicit defaults
  • The bare rules (i.e. implict defaults "spec.limits") is kept, but is now mutually exclusive with the above via CEL
  • RLP controller integrations tests now uses the explicit defaults in the RLP CR which test this functionality

Verification

Functionality is already tested by integration tests but if you want to verify functionality:

kubectl apply -f - <<EOF
apiVersion: kuadrant.io/v1beta2
kind: RateLimitPolicy
metadata:
  name: toystore
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: toystore
  defaults:
    limits:
      "create-toy":
        rates:
        - limit: 5
          duration: 10
          unit: second
        routeSelectors:
        - matches: # selects the 2nd HTTPRouteRule of the targeted route
          - method: POST
            path:
              type: Exact
              value: "/toys"
EOF
  • Verify guide completes successfully
  • Try creating a RLP with both implicit and explicit defaults:
kubectl apply -f  - <<EOF
apiVersion: kuadrant.io/v1beta2
kind: RateLimitPolicy
metadata:
  name: toystore
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: toystore
  defaults:
    limits:
      "create-toy":
        rates:
        - limit: 5
          duration: 10
          unit: second
  limits:
    "toy2":
      rates:
      - limit: 10
        duration: 20
        unit: second
EOF
  • Verify policy is rejected due to:
The RateLimitPolicy "toystore" is invalid: spec: Invalid value: "object": Implicit and explicit defaults are mutually exclusive

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Merging #456 (e66d50c) into main (ece13e8) will increase coverage by 0.06%.
The diff coverage is 87.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #456      +/-   ##
==========================================
+ Coverage   30.03%   30.10%   +0.06%     
==========================================
  Files          58       58              
  Lines        4132     4136       +4     
==========================================
+ Hits         1241     1245       +4     
  Misses       2822     2822              
  Partials       69       69              
Flag Coverage Δ
unit 30.10% <87.50%> (+0.06%) ⬆️

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

Components Coverage Δ
api/v1beta1 (u) ∅ <ø> (∅)
api/v1beta2 (u) 52.08% <80.00%> (+1.36%) ⬆️
pkg/common (u) 87.70% <ø> (ø)
pkg/istio (u) 41.61% <ø> (ø)
pkg/log (u) 36.84% <ø> (ø)
pkg/reconcilers (u) 38.20% <ø> (ø)
pkg/rlptools (u) 56.40% <100.00%> (ø)
controllers (i) 8.09% <ø> (ø)
Files Coverage Δ
pkg/rlptools/utils.go 100.00% <100.00%> (ø)
pkg/rlptools/wasm_utils.go 59.60% <100.00%> (ø)
api/v1beta2/ratelimitpolicy_types.go 22.03% <80.00%> (+5.67%) ⬆️

@KevFan KevFan force-pushed the rlp-do branch 9 times, most recently from 906dc2c to 6de620e Compare March 19, 2024 15:59
Comment on lines 56 to 53
Defaults: kuadrantv1beta2.CommonSpec{
Limits: map[string]kuadrantv1beta2.Limit{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other places such as limitador_cluster_envoyfilter_controller_test.go still use implicit limits to test the implicit path still works as intended

@KevFan KevFan changed the title [WIP] RLP Defaults RLP Defaults Mar 19, 2024
@KevFan KevFan marked this pull request as ready for review March 19, 2024 17:13
@KevFan KevFan requested a review from a team as a code owner March 19, 2024 17:13
@KevFan
Copy link
Contributor Author

KevFan commented Mar 19, 2024

Not sure what do we want to do with the guides, they still use the implicit default fields for RLP. Not sure do we want to update them to use the explicit default field instead 🤔

@KevFan KevFan added kind/enhancement New feature or request size/small area/api Changes user facing APIs labels Mar 20, 2024
@KevFan KevFan self-assigned this Mar 20, 2024
@KevFan KevFan force-pushed the rlp-do branch 3 times, most recently from cdc58b7 to 30a820e Compare March 27, 2024 16:53
Copy link
Contributor

@Boomatang Boomatang left a comment

Choose a reason for hiding this comment

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

TL:DR code works as expected.

The function of the code seems to be working as expected, however I do have a local issue with writing the RLP spec into the isisto gateway. Happens on main also. This meant that I could not follow the linked guide.

What I did observe was the limitador CR being update with the implicit or explicit defaults, which was expected. My assumption the kuadrant operator did write these changes to the wasm shim.

api/v1beta2/ratelimitpolicy_types.go Outdated Show resolved Hide resolved
@Boomatang Boomatang mentioned this pull request Apr 2, 2024
@KevFan KevFan force-pushed the rlp-do branch 4 times, most recently from 953ce0a to 5b04f4e Compare April 8, 2024 10:19
@KevFan
Copy link
Contributor Author

KevFan commented Apr 8, 2024

Rebased and resolved conflicts

@KevFan KevFan mentioned this pull request Apr 8, 2024
@@ -393,7 +393,7 @@ run: generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: ## Build docker image with the manager.
docker build -t $(IMG) .
docker build -t $(IMG) . --load
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If using podman runtime with docker cli also, there was the following warning locally for me:

 => CACHED [stage-1 2/3] COPY --from=builder /workspace/manager .                                                                                  0.0s
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load

This can cause the cluster to use an old build image as the newly built image is kept in cache only

@KevFan KevFan merged commit 241e50f into Kuadrant:main Apr 10, 2024
13 checks passed
philbrookes pushed a commit that referenced this pull request Apr 16, 2024
* feat: rlp default field

* refactor: rlp GetLimits based on implicit or default rules

* feat: rlp validation to prevent both implicit and explicit default rules

* refactor: CEL for validation of RLP implicit and explicit default mutual exclusivity

* refactor: use default limits field for rlp controller tests

* docs: update rlp reference

* refactor: common spec validation

* test: RLP atomic default integration test

* refactor: remove unneccessary getters

* fix: use common spec limits for wasm rules

* docs: address comments with new defaults field

* fix: load image for docker use explicitly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Changes user facing APIs kind/enhancement New feature or request size/small
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add the default field to the RateLimitPolicy API
3 participants