Skip to content

Commit

Permalink
ratelimitpolicy v1beta3 (#875)
Browse files Browse the repository at this point in the history
* ratelimitpolicy v1beta3

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* ratelimitpolicy v1beta3: unittests

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* ratelimitpolicy v1beta3: integration tests

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* ratelimitpolicy v1beta3: manifests

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* ratelimitpolicy v1beta3: more integration tests

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* fix unittests

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* remove routeSelectors from v1beta3

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* helm chart update

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* add some unittets regarding wasm rule generation

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

* removed integration tests regarding routeselectors

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>

---------

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
  • Loading branch information
eguzki authored Oct 7, 2024
1 parent 9992a27 commit c194aa4
Show file tree
Hide file tree
Showing 49 changed files with 1,087 additions and 4,092 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ endef

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd paths="./api/v1alpha1;./api/v1beta1;./api/v1beta2" output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) crd paths="./api/v1alpha1;./api/v1beta1;./api/v1beta2;./api/v1beta3" output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..."

.PHONY: dependencies-manifests
Expand Down
31 changes: 2 additions & 29 deletions api/v1beta2/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
)

var (
AuthPoliciesResource = GroupVersion.WithResource("authpolicies")
AuthPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "AuthPolicy"}
RateLimitPoliciesResource = GroupVersion.WithResource("ratelimitpolicies")
RateLimitPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "RateLimitPolicy"}
AuthPoliciesResource = GroupVersion.WithResource("authpolicies")
AuthPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "AuthPolicy"}
)

var _ machinery.Policy = &AuthPolicy{}
Expand All @@ -38,28 +36,3 @@ func (ap *AuthPolicy) Merge(other machinery.Policy) machinery.Policy {
func (ap *AuthPolicy) GetLocator() string {
return machinery.LocatorFromObject(ap)
}

var _ machinery.Policy = &RateLimitPolicy{}

func (r *RateLimitPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
return []machinery.PolicyTargetReference{
machinery.LocalPolicyTargetReference{
LocalPolicyTargetReference: r.Spec.TargetRef,
PolicyNamespace: r.Namespace,
},
}
}

func (r *RateLimitPolicy) GetMergeStrategy() machinery.MergeStrategy {
return func(policy machinery.Policy, _ machinery.Policy) machinery.Policy {
return policy
}
}

func (r *RateLimitPolicy) Merge(other machinery.Policy) machinery.Policy {
return other
}

func (r *RateLimitPolicy) GetLocator() string {
return machinery.LocatorFromObject(r)
}
198 changes: 0 additions & 198 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions api/v1beta3/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta3 contains API Schema definitions for the kuadrant v1beta3 API group
// +kubebuilder:object:generate=true
// +groupName=kuadrant.io
package v1beta3

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "kuadrant.io", Version: "v1beta3"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta2
package v1beta3

import (
"context"
Expand Down Expand Up @@ -87,7 +87,7 @@ type Rate struct {
Unit TimeUnit `json:"unit"`
}

// RouteSelector defines semantics for matching an HTTP request based on conditions
// WhenCondition defines semantics for matching an HTTP request based on conditions
// https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteSpec
type WhenCondition struct {
// Selector defines one item from the well known selectors
Expand All @@ -104,11 +104,6 @@ type WhenCondition struct {

// Limit represents a complete rate limit configuration
type Limit struct {
// RouteSelectors defines semantics for matching an HTTP request based on conditions
// +optional
// +kubebuilder:validation:MaxItems=15
RouteSelectors []RouteSelector `json:"routeSelectors,omitempty"`

// When holds the list of conditions for the policy to be enforced.
// Called also "soft" conditions as route selectors must also match
// +optional
Expand All @@ -132,7 +127,6 @@ func (l Limit) CountersAsStringList() []string {
}

// RateLimitPolicySpec defines the desired state of RateLimitPolicy
// +kubebuilder:validation:XValidation:rule="self.targetRef.kind != 'Gateway' || !has(self.limits) || !self.limits.exists(x, has(self.limits[x].routeSelectors))",message="route selectors not supported when targeting a Gateway"
// +kubebuilder:validation:XValidation:rule="!(has(self.defaults) && has(self.limits))",message="Implicit and explicit defaults are mutually exclusive"
// +kubebuilder:validation:XValidation:rule="!(has(self.defaults) && has(self.overrides))",message="Overrides and explicit defaults are mutually exclusive"
// +kubebuilder:validation:XValidation:rule="!(has(self.overrides) && has(self.limits))",message="Overrides and implicit defaults are mutually exclusive"
Expand Down Expand Up @@ -266,18 +260,6 @@ func (r *RateLimitPolicy) GetWrappedNamespace() gatewayapiv1.Namespace {

func (r *RateLimitPolicy) GetRulesHostnames() (ruleHosts []string) {
ruleHosts = make([]string, 0)
for _, limit := range r.Spec.CommonSpec().Limits {
for _, routeSelector := range limit.RouteSelectors {
convertHostnamesToString := func(gwHostnames []gatewayapiv1.Hostname) []string {
hostnames := make([]string, 0, len(gwHostnames))
for _, gwHostName := range gwHostnames {
hostnames = append(hostnames, string(gwHostName))
}
return hostnames
}
ruleHosts = append(ruleHosts, convertHostnamesToString(routeSelector.Hostnames)...)
}
}
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build unit

package v1beta2
package v1beta3

import (
"testing"
Expand Down
Loading

0 comments on commit c194aa4

Please sign in to comment.