diff --git a/Makefile b/Makefile index 6c237fcc7..55d1d6e12 100644 --- a/Makefile +++ b/Makefile @@ -299,7 +299,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 diff --git a/api/v1beta2/route_selectors.go b/api/v1beta2/route_selectors.go index ef494effa..9689391e6 100644 --- a/api/v1beta2/route_selectors.go +++ b/api/v1beta2/route_selectors.go @@ -1,73 +1,11 @@ package v1beta2 import ( - "github.com/elliotchance/orderedmap/v2" - gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - - "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" - "github.com/kuadrant/kuadrant-operator/pkg/library/utils" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" ) -// RouteSelector 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 RouteSelector struct { - // Hostnames defines a set of hostname that should match against the HTTP Host header to select a HTTPRoute to process the request - // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteSpec - // +optional - Hostnames []gatewayapiv1.Hostname `json:"hostnames,omitempty"` - - // Matches define conditions used for matching the rule against incoming HTTP requests. - // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteSpec - // +optional - // +kubebuilder:validation:MaxItems=8 - Matches []gatewayapiv1.HTTPRouteMatch `json:"matches,omitempty"` -} - -// SelectRules returns, from a HTTPRoute, all HTTPRouteRules that either specify no HTTRouteMatches or that contain at -// least one HTTRouteMatch whose statements expressly include (partially or totally) the statements of at least one of -// the matches of the selector. If the selector does not specify any matches, then all HTTPRouteRules are selected. -// -// Additionally, if the selector specifies a non-empty list of hostnames, a non-empty intersection between the literal -// hostnames of the selector and set of hostnames specified in the HTTPRoute must exist. Otherwise, the function -// returns nil. -func (s *RouteSelector) SelectRules(route *gatewayapiv1.HTTPRoute) (rules []gatewayapiv1.HTTPRouteRule) { - rulesIndices := orderedmap.NewOrderedMap[int, gatewayapiv1.HTTPRouteRule]() - if len(s.Hostnames) > 0 && !utils.Intersect(s.Hostnames, route.Spec.Hostnames) { - return nil - } - if len(s.Matches) == 0 { - return route.Spec.Rules - } - for idx := range s.Matches { - routeSelectorMatch := s.Matches[idx] - for idx, rule := range route.Spec.Rules { - rs := kuadrant.HTTPRouteRuleSelector{HTTPRouteMatch: &routeSelectorMatch} - if rs.Selects(rule) { - rulesIndices.Set(idx, rule) - } - } - } - for el := rulesIndices.Front(); el != nil; el = el.Next() { - rules = append(rules, el.Value) - } - return -} - -// HostnamesForConditions allows avoiding building conditions for hostnames that are excluded by the selector -// or when the hostname is irrelevant (i.e. matches all hostnames) -func (s *RouteSelector) HostnamesForConditions(route *gatewayapiv1.HTTPRoute) []gatewayapiv1.Hostname { - hostnames := route.Spec.Hostnames - - if len(s.Hostnames) > 0 { - hostnames = utils.Intersection(s.Hostnames, hostnames) - } - - if utils.SameElements(hostnames, route.Spec.Hostnames) { - return []gatewayapiv1.Hostname{"*"} - } - - return hostnames -} +// +kubebuilder:object:generate=false +type RouteSelector = kuadrantv1beta3.RouteSelector // +kubebuilder:object:generate=false type RouteSelectorsGetter interface { diff --git a/api/v1beta2/topology.go b/api/v1beta2/topology.go index ea622c47b..d46c07f61 100644 --- a/api/v1beta2/topology.go +++ b/api/v1beta2/topology.go @@ -8,10 +8,8 @@ import ( ) var ( - AuthPoliciesResource = GroupVersion.WithResource("authpolicies") - AuthPolicyKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "AuthPolicy"} - RateLimitPoliciesResource = GroupVersion.WithResource("ratelimitpolicies") - RateLimitPolicyKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "RateLimitPolicy"} + AuthPoliciesResource = GroupVersion.WithResource("authpolicies") + AuthPolicyKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "AuthPolicy"} ) var _ machinery.Policy = &AuthPolicy{} @@ -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) -} diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 3ca4e42ef..3f58b7306 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -22,9 +22,9 @@ package v1beta2 import ( apiv1beta2 "github.com/kuadrant/authorino/api/v1beta2" + "github.com/kuadrant/kuadrant-operator/api/v1beta3" "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" - apisv1 "sigs.k8s.io/gateway-api/apis/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -59,7 +59,7 @@ func (in *AuthPolicyCommonSpec) DeepCopyInto(out *AuthPolicyCommonSpec) { *out = *in if in.RouteSelectors != nil { in, out := &in.RouteSelectors, &out.RouteSelectors - *out = make([]RouteSelector, len(*in)) + *out = make([]v1beta3.RouteSelector, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -289,7 +289,7 @@ func (in *CommonAuthRuleSpec) DeepCopyInto(out *CommonAuthRuleSpec) { *out = *in if in.RouteSelectors != nil { in, out := &in.RouteSelectors, &out.RouteSelectors - *out = make([]RouteSelector, len(*in)) + *out = make([]v1beta3.RouteSelector, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -322,43 +322,6 @@ func (in *HeaderSuccessResponseSpec) DeepCopy() *HeaderSuccessResponseSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Limit) DeepCopyInto(out *Limit) { - *out = *in - if in.RouteSelectors != nil { - in, out := &in.RouteSelectors, &out.RouteSelectors - *out = make([]RouteSelector, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.When != nil { - in, out := &in.When, &out.When - *out = make([]WhenCondition, len(*in)) - copy(*out, *in) - } - if in.Counters != nil { - in, out := &in.Counters, &out.Counters - *out = make([]ContextSelector, len(*in)) - copy(*out, *in) - } - if in.Rates != nil { - in, out := &in.Rates, &out.Rates - *out = make([]Rate, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Limit. -func (in *Limit) DeepCopy() *Limit { - if in == nil { - return nil - } - out := new(Limit) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MetadataSpec) DeepCopyInto(out *MetadataSpec) { *out = *in @@ -376,152 +339,6 @@ func (in *MetadataSpec) DeepCopy() *MetadataSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Rate) DeepCopyInto(out *Rate) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rate. -func (in *Rate) DeepCopy() *Rate { - if in == nil { - return nil - } - out := new(Rate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RateLimitPolicy) DeepCopyInto(out *RateLimitPolicy) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicy. -func (in *RateLimitPolicy) DeepCopy() *RateLimitPolicy { - if in == nil { - return nil - } - out := new(RateLimitPolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RateLimitPolicy) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RateLimitPolicyCommonSpec) DeepCopyInto(out *RateLimitPolicyCommonSpec) { - *out = *in - if in.Limits != nil { - in, out := &in.Limits, &out.Limits - *out = make(map[string]Limit, len(*in)) - for key, val := range *in { - (*out)[key] = *val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyCommonSpec. -func (in *RateLimitPolicyCommonSpec) DeepCopy() *RateLimitPolicyCommonSpec { - if in == nil { - return nil - } - out := new(RateLimitPolicyCommonSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RateLimitPolicyList) DeepCopyInto(out *RateLimitPolicyList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]RateLimitPolicy, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyList. -func (in *RateLimitPolicyList) DeepCopy() *RateLimitPolicyList { - if in == nil { - return nil - } - out := new(RateLimitPolicyList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RateLimitPolicyList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RateLimitPolicySpec) DeepCopyInto(out *RateLimitPolicySpec) { - *out = *in - out.TargetRef = in.TargetRef - if in.Defaults != nil { - in, out := &in.Defaults, &out.Defaults - *out = new(RateLimitPolicyCommonSpec) - (*in).DeepCopyInto(*out) - } - if in.Overrides != nil { - in, out := &in.Overrides, &out.Overrides - *out = new(RateLimitPolicyCommonSpec) - (*in).DeepCopyInto(*out) - } - in.RateLimitPolicyCommonSpec.DeepCopyInto(&out.RateLimitPolicyCommonSpec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicySpec. -func (in *RateLimitPolicySpec) DeepCopy() *RateLimitPolicySpec { - if in == nil { - return nil - } - out := new(RateLimitPolicySpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RateLimitPolicyStatus) DeepCopyInto(out *RateLimitPolicyStatus) { - *out = *in - out.StatusMeta = in.StatusMeta - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]v1.Condition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyStatus. -func (in *RateLimitPolicyStatus) DeepCopy() *RateLimitPolicyStatus { - if in == nil { - return nil - } - out := new(RateLimitPolicyStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResponseSpec) DeepCopyInto(out *ResponseSpec) { *out = *in @@ -548,33 +365,6 @@ func (in *ResponseSpec) DeepCopy() *ResponseSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RouteSelector) DeepCopyInto(out *RouteSelector) { - *out = *in - if in.Hostnames != nil { - in, out := &in.Hostnames, &out.Hostnames - *out = make([]apisv1.Hostname, len(*in)) - copy(*out, *in) - } - if in.Matches != nil { - in, out := &in.Matches, &out.Matches - *out = make([]apisv1.HTTPRouteMatch, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteSelector. -func (in *RouteSelector) DeepCopy() *RouteSelector { - if in == nil { - return nil - } - out := new(RouteSelector) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SuccessResponseSpec) DeepCopyInto(out *SuccessResponseSpec) { *out = *in @@ -592,21 +382,6 @@ func (in *SuccessResponseSpec) DeepCopy() *SuccessResponseSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *WhenCondition) DeepCopyInto(out *WhenCondition) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WhenCondition. -func (in *WhenCondition) DeepCopy() *WhenCondition { - if in == nil { - return nil - } - out := new(WhenCondition) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WrappedSuccessResponseSpec) DeepCopyInto(out *WrappedSuccessResponseSpec) { *out = *in diff --git a/api/v1beta3/groupversion_info.go b/api/v1beta3/groupversion_info.go new file mode 100644 index 000000000..518ca630c --- /dev/null +++ b/api/v1beta3/groupversion_info.go @@ -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 +) diff --git a/api/v1beta2/ratelimitpolicy_types.go b/api/v1beta3/ratelimitpolicy_types.go similarity index 99% rename from api/v1beta2/ratelimitpolicy_types.go rename to api/v1beta3/ratelimitpolicy_types.go index 8dbe8e5f0..d5dd195c4 100644 --- a/api/v1beta2/ratelimitpolicy_types.go +++ b/api/v1beta3/ratelimitpolicy_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta2 +package v1beta3 import ( "context" diff --git a/api/v1beta2/ratelimitpolicy_types_test.go b/api/v1beta3/ratelimitpolicy_types_test.go similarity index 99% rename from api/v1beta2/ratelimitpolicy_types_test.go rename to api/v1beta3/ratelimitpolicy_types_test.go index 73605e161..4e5e28781 100644 --- a/api/v1beta2/ratelimitpolicy_types_test.go +++ b/api/v1beta3/ratelimitpolicy_types_test.go @@ -1,6 +1,6 @@ //go:build unit -package v1beta2 +package v1beta3 import ( "testing" diff --git a/api/v1beta3/route_selectors.go b/api/v1beta3/route_selectors.go new file mode 100644 index 000000000..24d3c2044 --- /dev/null +++ b/api/v1beta3/route_selectors.go @@ -0,0 +1,75 @@ +package v1beta3 + +import ( + "github.com/elliotchance/orderedmap/v2" + gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" + + "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" + "github.com/kuadrant/kuadrant-operator/pkg/library/utils" +) + +// RouteSelector 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 RouteSelector struct { + // Hostnames defines a set of hostname that should match against the HTTP Host header to select a HTTPRoute to process the request + // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteSpec + // +optional + Hostnames []gatewayapiv1.Hostname `json:"hostnames,omitempty"` + + // Matches define conditions used for matching the rule against incoming HTTP requests. + // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteSpec + // +optional + // +kubebuilder:validation:MaxItems=8 + Matches []gatewayapiv1.HTTPRouteMatch `json:"matches,omitempty"` +} + +// SelectRules returns, from a HTTPRoute, all HTTPRouteRules that either specify no HTTRouteMatches or that contain at +// least one HTTRouteMatch whose statements expressly include (partially or totally) the statements of at least one of +// the matches of the selector. If the selector does not specify any matches, then all HTTPRouteRules are selected. +// +// Additionally, if the selector specifies a non-empty list of hostnames, a non-empty intersection between the literal +// hostnames of the selector and set of hostnames specified in the HTTPRoute must exist. Otherwise, the function +// returns nil. +func (s *RouteSelector) SelectRules(route *gatewayapiv1.HTTPRoute) (rules []gatewayapiv1.HTTPRouteRule) { + rulesIndices := orderedmap.NewOrderedMap[int, gatewayapiv1.HTTPRouteRule]() + if len(s.Hostnames) > 0 && !utils.Intersect(s.Hostnames, route.Spec.Hostnames) { + return nil + } + if len(s.Matches) == 0 { + return route.Spec.Rules + } + for idx := range s.Matches { + routeSelectorMatch := s.Matches[idx] + for idx, rule := range route.Spec.Rules { + rs := kuadrant.HTTPRouteRuleSelector{HTTPRouteMatch: &routeSelectorMatch} + if rs.Selects(rule) { + rulesIndices.Set(idx, rule) + } + } + } + for el := rulesIndices.Front(); el != nil; el = el.Next() { + rules = append(rules, el.Value) + } + return +} + +// HostnamesForConditions allows avoiding building conditions for hostnames that are excluded by the selector +// or when the hostname is irrelevant (i.e. matches all hostnames) +func (s *RouteSelector) HostnamesForConditions(route *gatewayapiv1.HTTPRoute) []gatewayapiv1.Hostname { + hostnames := route.Spec.Hostnames + + if len(s.Hostnames) > 0 { + hostnames = utils.Intersection(s.Hostnames, hostnames) + } + + if utils.SameElements(hostnames, route.Spec.Hostnames) { + return []gatewayapiv1.Hostname{"*"} + } + + return hostnames +} + +// +kubebuilder:object:generate=false +type RouteSelectorsGetter interface { + GetRouteSelectors() []RouteSelector +} diff --git a/api/v1beta2/route_selectors_test.go b/api/v1beta3/route_selectors_test.go similarity index 99% rename from api/v1beta2/route_selectors_test.go rename to api/v1beta3/route_selectors_test.go index c3934b86f..0b5e48054 100644 --- a/api/v1beta2/route_selectors_test.go +++ b/api/v1beta3/route_selectors_test.go @@ -1,6 +1,6 @@ //go:build unit -package v1beta2 +package v1beta3 import ( "fmt" diff --git a/api/v1beta3/topology.go b/api/v1beta3/topology.go new file mode 100644 index 000000000..df9f6bb5e --- /dev/null +++ b/api/v1beta3/topology.go @@ -0,0 +1,38 @@ +package v1beta3 + +// Contains of this file allow the AuthPolicy and RateLimitPolicy to adhere to the machinery.Policy interface + +import ( + "github.com/kuadrant/policy-machinery/machinery" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + RateLimitPoliciesResource = GroupVersion.WithResource("ratelimitpolicies") + RateLimitPolicyKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "RateLimitPolicy"} +) + +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) +} diff --git a/api/v1beta3/zz_generated.deepcopy.go b/api/v1beta3/zz_generated.deepcopy.go new file mode 100644 index 000000000..0c19fe0a0 --- /dev/null +++ b/api/v1beta3/zz_generated.deepcopy.go @@ -0,0 +1,252 @@ +//go:build !ignore_autogenerated + +/* +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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1beta3 + +import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + apisv1 "sigs.k8s.io/gateway-api/apis/v1" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Limit) DeepCopyInto(out *Limit) { + *out = *in + if in.RouteSelectors != nil { + in, out := &in.RouteSelectors, &out.RouteSelectors + *out = make([]RouteSelector, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.When != nil { + in, out := &in.When, &out.When + *out = make([]WhenCondition, len(*in)) + copy(*out, *in) + } + if in.Counters != nil { + in, out := &in.Counters, &out.Counters + *out = make([]ContextSelector, len(*in)) + copy(*out, *in) + } + if in.Rates != nil { + in, out := &in.Rates, &out.Rates + *out = make([]Rate, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Limit. +func (in *Limit) DeepCopy() *Limit { + if in == nil { + return nil + } + out := new(Limit) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Rate) DeepCopyInto(out *Rate) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rate. +func (in *Rate) DeepCopy() *Rate { + if in == nil { + return nil + } + out := new(Rate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RateLimitPolicy) DeepCopyInto(out *RateLimitPolicy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicy. +func (in *RateLimitPolicy) DeepCopy() *RateLimitPolicy { + if in == nil { + return nil + } + out := new(RateLimitPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RateLimitPolicy) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RateLimitPolicyCommonSpec) DeepCopyInto(out *RateLimitPolicyCommonSpec) { + *out = *in + if in.Limits != nil { + in, out := &in.Limits, &out.Limits + *out = make(map[string]Limit, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyCommonSpec. +func (in *RateLimitPolicyCommonSpec) DeepCopy() *RateLimitPolicyCommonSpec { + if in == nil { + return nil + } + out := new(RateLimitPolicyCommonSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RateLimitPolicyList) DeepCopyInto(out *RateLimitPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]RateLimitPolicy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyList. +func (in *RateLimitPolicyList) DeepCopy() *RateLimitPolicyList { + if in == nil { + return nil + } + out := new(RateLimitPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RateLimitPolicyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RateLimitPolicySpec) DeepCopyInto(out *RateLimitPolicySpec) { + *out = *in + out.TargetRef = in.TargetRef + if in.Defaults != nil { + in, out := &in.Defaults, &out.Defaults + *out = new(RateLimitPolicyCommonSpec) + (*in).DeepCopyInto(*out) + } + if in.Overrides != nil { + in, out := &in.Overrides, &out.Overrides + *out = new(RateLimitPolicyCommonSpec) + (*in).DeepCopyInto(*out) + } + in.RateLimitPolicyCommonSpec.DeepCopyInto(&out.RateLimitPolicyCommonSpec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicySpec. +func (in *RateLimitPolicySpec) DeepCopy() *RateLimitPolicySpec { + if in == nil { + return nil + } + out := new(RateLimitPolicySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RateLimitPolicyStatus) DeepCopyInto(out *RateLimitPolicyStatus) { + *out = *in + out.StatusMeta = in.StatusMeta + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]v1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitPolicyStatus. +func (in *RateLimitPolicyStatus) DeepCopy() *RateLimitPolicyStatus { + if in == nil { + return nil + } + out := new(RateLimitPolicyStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouteSelector) DeepCopyInto(out *RouteSelector) { + *out = *in + if in.Hostnames != nil { + in, out := &in.Hostnames, &out.Hostnames + *out = make([]apisv1.Hostname, len(*in)) + copy(*out, *in) + } + if in.Matches != nil { + in, out := &in.Matches, &out.Matches + *out = make([]apisv1.HTTPRouteMatch, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteSelector. +func (in *RouteSelector) DeepCopy() *RouteSelector { + if in == nil { + return nil + } + out := new(RouteSelector) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WhenCondition) DeepCopyInto(out *WhenCondition) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WhenCondition. +func (in *WhenCondition) DeepCopy() *WhenCondition { + if in == nil { + return nil + } + out := new(WhenCondition) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml index 35a23e824..77de10a83 100644 --- a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml +++ b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml @@ -40,7 +40,7 @@ spec: - jsonPath: .metadata.creationTimestamp name: Age type: date - name: v1beta2 + name: v1beta3 schema: openAPIV3Schema: description: RateLimitPolicy enables rate limiting for service workloads in diff --git a/controllers/envoygateway_wasm_controller.go b/controllers/envoygateway_wasm_controller.go index 6c9a0133f..42fd89350 100644 --- a/controllers/envoygateway_wasm_controller.go +++ b/controllers/envoygateway_wasm_controller.go @@ -16,7 +16,7 @@ import ( gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" kuadrantenvoygateway "github.com/kuadrant/kuadrant-operator/pkg/envoygateway" "github.com/kuadrant/kuadrant-operator/pkg/kuadranttools" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" @@ -55,7 +55,7 @@ func (r *EnvoyGatewayWasmReconciler) Reconcile(eventCtx context.Context, req ctr return ctrl.Result{}, err } - rawTopology, err := kuadranttools.TopologyForPolicies(ctx, r.Client(), kuadrantv1beta2.NewRateLimitPolicyType()) + rawTopology, err := kuadranttools.TopologyForPolicies(ctx, r.Client(), kuadrantv1beta3.NewRateLimitPolicyType()) if err != nil { return ctrl.Result{}, err } @@ -206,7 +206,7 @@ func (r *EnvoyGatewayWasmReconciler) SetupWithManager(mgr ctrl.Manager) error { handler.EnqueueRequestsFromMapFunc(kuadrantListEventMapper.Map), ). Watches( - &kuadrantv1beta2.RateLimitPolicy{}, + &kuadrantv1beta3.RateLimitPolicy{}, handler.EnqueueRequestsFromMapFunc(policyToKuadrantEventMapper.Map), ). Watches( diff --git a/controllers/httprouteparentrefs_eventmapper.go b/controllers/httprouteparentrefs_eventmapper.go index 410b43882..6e7b83a4e 100644 --- a/controllers/httprouteparentrefs_eventmapper.go +++ b/controllers/httprouteparentrefs_eventmapper.go @@ -10,7 +10,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - api "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" ) @@ -24,11 +25,11 @@ type HTTPRouteParentRefsEventMapper struct { } func (m *HTTPRouteParentRefsEventMapper) MapToRateLimitPolicy(obj client.Object) []reconcile.Request { - return m.mapToPolicyRequest(obj, "ratelimitpolicy", &api.RateLimitPolicyList{}) + return m.mapToPolicyRequest(obj, "ratelimitpolicy", &kuadrantv1beta3.RateLimitPolicyList{}) } func (m *HTTPRouteParentRefsEventMapper) MapToAuthPolicy(obj client.Object) []reconcile.Request { - return m.mapToPolicyRequest(obj, "authpolicy", &api.AuthPolicyList{}) + return m.mapToPolicyRequest(obj, "authpolicy", &kuadrantv1beta2.AuthPolicyList{}) } func (m *HTTPRouteParentRefsEventMapper) mapToPolicyRequest(obj client.Object, policyKind string, policyList client.ObjectList) []reconcile.Request { diff --git a/controllers/limitador_cluster_envoyfilter_controller.go b/controllers/limitador_cluster_envoyfilter_controller.go index 9ef3968d0..689221dcf 100644 --- a/controllers/limitador_cluster_envoyfilter_controller.go +++ b/controllers/limitador_cluster_envoyfilter_controller.go @@ -34,7 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/common" kuadrantistioutils "github.com/kuadrant/kuadrant-operator/pkg/istio" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" @@ -124,7 +124,7 @@ func (r *LimitadorClusterEnvoyFilterReconciler) desiredRateLimitingClusterEnvoyF }, } - gateway := kuadrant.GatewayWrapper{Gateway: gw, Referrer: &v1beta2.RateLimitPolicy{}} + gateway := kuadrant.GatewayWrapper{Gateway: gw, Referrer: &kuadrantv1beta3.RateLimitPolicy{}} rlpRefs := gateway.PolicyRefs() logger.V(1).Info("desiredRateLimitingClusterEnvoyFilter", "rlpRefs", rlpRefs) diff --git a/controllers/limitador_status_to_rlp_gateway_event_handler.go b/controllers/limitador_status_to_rlp_gateway_event_handler.go index d7a6ed9ba..a3562a342 100644 --- a/controllers/limitador_status_to_rlp_gateway_event_handler.go +++ b/controllers/limitador_status_to_rlp_gateway_event_handler.go @@ -12,7 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/common" "github.com/kuadrant/kuadrant-operator/pkg/library/mappers" ) @@ -71,7 +71,7 @@ func (eh limitadorStatusRLPGatewayEventHandler) IsKuadrantInstalled(ctx context. } func (eh limitadorStatusRLPGatewayEventHandler) enqueue(ctx context.Context, limitingInterface workqueue.RateLimitingInterface) { // List all RLPs as there's been an event from Limitador which may affect RLP status - rlpList := &kuadrantv1beta2.RateLimitPolicyList{} + rlpList := &kuadrantv1beta3.RateLimitPolicyList{} if err := eh.Client.List(ctx, rlpList); err != nil { eh.Logger.V(1).Error(err, "failed to list RLPs") } diff --git a/controllers/rate_limiting_istio_wasmplugin_controller.go b/controllers/rate_limiting_istio_wasmplugin_controller.go index 5c43f8738..2b3374fd8 100644 --- a/controllers/rate_limiting_istio_wasmplugin_controller.go +++ b/controllers/rate_limiting_istio_wasmplugin_controller.go @@ -33,7 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" kuadrantistioutils "github.com/kuadrant/kuadrant-operator/pkg/istio" "github.com/kuadrant/kuadrant-operator/pkg/kuadranttools" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" @@ -154,7 +154,7 @@ func (r *RateLimitingIstioWASMPluginReconciler) desiredRateLimitingWASMPlugin(ct } func (r *RateLimitingIstioWASMPluginReconciler) wasmPluginConfig(ctx context.Context, gw *gatewayapiv1.Gateway) (*wasm.Config, error) { - rawTopology, err := kuadranttools.TopologyFromGateway(ctx, r.Client(), gw, kuadrantv1beta2.NewRateLimitPolicyType()) + rawTopology, err := kuadranttools.TopologyFromGateway(ctx, r.Client(), gw, kuadrantv1beta3.NewRateLimitPolicyType()) if err != nil { return nil, err } @@ -216,7 +216,7 @@ func (r *RateLimitingIstioWASMPluginReconciler) SetupWithManager(mgr ctrl.Manage handler.EnqueueRequestsFromMapFunc(httpRouteToParentGatewaysEventMapper.Map), ). Watches( - &kuadrantv1beta2.RateLimitPolicy{}, + &kuadrantv1beta3.RateLimitPolicy{}, handler.EnqueueRequestsFromMapFunc(rlpToParentGatewaysEventMapper.Map), ). Complete(r) diff --git a/controllers/ratelimitpolicy_controller.go b/controllers/ratelimitpolicy_controller.go index 7ff89970a..0a390eee2 100644 --- a/controllers/ratelimitpolicy_controller.go +++ b/controllers/ratelimitpolicy_controller.go @@ -31,7 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" "github.com/kuadrant/kuadrant-operator/pkg/library/mappers" @@ -66,7 +66,7 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl ctx := logr.NewContext(eventCtx, logger) // fetch the ratelimitpolicy - rlp := &kuadrantv1beta2.RateLimitPolicy{} + rlp := &kuadrantv1beta3.RateLimitPolicy{} if err := r.Client().Get(ctx, req.NamespacedName, rlp); err != nil { if apierrors.IsNotFound(err) { logger.Info("no RateLimitPolicy found") @@ -153,7 +153,7 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl } // validate performs validation before proceeding with the reconcile loop, returning a common.ErrInvalid on failing validation -func (r *RateLimitPolicyReconciler) validate(rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error { +func (r *RateLimitPolicyReconciler) validate(rlp *kuadrantv1beta3.RateLimitPolicy, targetNetworkObject client.Object) error { if err := kuadrant.ValidateHierarchicalRules(rlp, targetNetworkObject); err != nil { return kuadrant.NewErrInvalid(rlp.Kind(), err) } @@ -161,7 +161,7 @@ func (r *RateLimitPolicyReconciler) validate(rlp *kuadrantv1beta2.RateLimitPolic return nil } -func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error { +func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy, targetNetworkObject client.Object) error { if err := r.validate(rlp, targetNetworkObject); err != nil { return err } @@ -189,7 +189,7 @@ func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp return nil } -func (r *RateLimitPolicyReconciler) deleteResources(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error { +func (r *RateLimitPolicyReconciler) deleteResources(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy, targetNetworkObject client.Object) error { // delete based on gateway diffs gatewayDiffObj, err := reconcilers.ComputeGatewayDiffs(ctx, r.Client(), rlp, targetNetworkObject) if err != nil { @@ -212,11 +212,11 @@ func (r *RateLimitPolicyReconciler) deleteResources(ctx context.Context, rlp *ku } // Ensures only one RLP targets the network resource -func (r *RateLimitPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx context.Context, policy *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error { +func (r *RateLimitPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx context.Context, policy *kuadrantv1beta3.RateLimitPolicy, targetNetworkObject client.Object) error { return r.TargetRefReconciler.ReconcileTargetBackReference(ctx, policy, targetNetworkObject, policy.DirectReferenceAnnotationName()) } -func (r *RateLimitPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object, policy *kuadrantv1beta2.RateLimitPolicy) error { +func (r *RateLimitPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object, policy *kuadrantv1beta3.RateLimitPolicy) error { return r.TargetRefReconciler.DeleteTargetBackReference(ctx, targetNetworkObject, policy.DirectReferenceAnnotationName()) } @@ -233,17 +233,17 @@ func (r *RateLimitPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { httpRouteEventMapper := mappers.NewHTTPRouteEventMapper(mappers.WithLogger(r.Logger().WithName("httproute.mapper")), mappers.WithClient(mgr.GetClient())) gatewayEventMapper := mappers.NewGatewayEventMapper( - kuadrantv1beta2.NewRateLimitPolicyType(), + kuadrantv1beta3.NewRateLimitPolicyType(), mappers.WithLogger(r.Logger().WithName("gateway.mapper")), mappers.WithClient(mgr.GetClient()), ) return ctrl.NewControllerManagedBy(mgr). - For(&kuadrantv1beta2.RateLimitPolicy{}). + For(&kuadrantv1beta3.RateLimitPolicy{}). Watches( &gatewayapiv1.HTTPRoute{}, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request { - return httpRouteEventMapper.MapToPolicy(ctx, object, kuadrantv1beta2.NewRateLimitPolicyType()) + return httpRouteEventMapper.MapToPolicy(ctx, object, kuadrantv1beta3.NewRateLimitPolicyType()) }), ). // Currently the purpose is to generate events when rlp references change in gateways diff --git a/controllers/ratelimitpolicy_enforced_status_controller.go b/controllers/ratelimitpolicy_enforced_status_controller.go index aea1a36c8..d446262d0 100644 --- a/controllers/ratelimitpolicy_enforced_status_controller.go +++ b/controllers/ratelimitpolicy_enforced_status_controller.go @@ -8,7 +8,6 @@ import ( "github.com/go-logr/logr" "github.com/google/uuid" - limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" "github.com/samber/lo" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -23,7 +22,9 @@ import ( gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" + + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/library/fieldindexers" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" @@ -82,7 +83,7 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) Reconcile(eventCtx context.Con for i := range policies { policy := policies[i] rlpKey := client.ObjectKeyFromObject(policy) - rlp := policy.(*kuadrantv1beta2.RateLimitPolicy) + rlp := policy.(*kuadrantv1beta3.RateLimitPolicy) conditions := rlp.GetStatus().GetConditions() // skip policy if accepted condition is false @@ -136,7 +137,7 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) Reconcile(eventCtx context.Con var gatewayParentOverridePolicies []kuadrantgatewayapi.Policy gatewayParentsWithOverrides := utils.Filter(gatewayParents, func(gatewayParent *gatewayapiv1.Gateway) bool { _, found := utils.Find(indexes.PoliciesFromGateway(gatewayParent), func(p kuadrantgatewayapi.Policy) bool { - rlp := p.(*kuadrantv1beta2.RateLimitPolicy) + rlp := p.(*kuadrantv1beta3.RateLimitPolicy) if kuadrantgatewayapi.IsTargetRefGateway(p.GetTargetRef()) && rlp != nil && rlp.Spec.Overrides != nil { gatewayParentOverridePolicies = append(gatewayParentOverridePolicies, p) return true @@ -192,7 +193,7 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) buildTopology(ctx context.Cont return nil, err } - policyList := &kuadrantv1beta2.RateLimitPolicyList{} + policyList := &kuadrantv1beta3.RateLimitPolicyList{} err = r.Client().List(ctx, policyList) logger.V(1).Info("list rate limit policies", "#policies", len(policyList.Items), "err", err) if err != nil { @@ -203,12 +204,12 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) buildTopology(ctx context.Cont kuadrantgatewayapi.WithAcceptedRoutesLinkedOnly(), kuadrantgatewayapi.WithGateways(utils.Map(gatewayList.Items, ptr.To[gatewayapiv1.Gateway])), kuadrantgatewayapi.WithRoutes(utils.Map(routeList.Items, ptr.To[gatewayapiv1.HTTPRoute])), - kuadrantgatewayapi.WithPolicies(utils.Map(policyList.Items, func(p kuadrantv1beta2.RateLimitPolicy) kuadrantgatewayapi.Policy { return &p })), + kuadrantgatewayapi.WithPolicies(utils.Map(policyList.Items, func(p kuadrantv1beta3.RateLimitPolicy) kuadrantgatewayapi.Policy { return &p })), kuadrantgatewayapi.WithLogger(logger), ) } -func (r *RateLimitPolicyEnforcedStatusReconciler) hasErrCondOnSubResource(ctx context.Context, p *kuadrantv1beta2.RateLimitPolicy) *metav1.Condition { +func (r *RateLimitPolicyEnforcedStatusReconciler) hasErrCondOnSubResource(ctx context.Context, p *kuadrantv1beta3.RateLimitPolicy) *metav1.Condition { logger, err := logr.FromContext(ctx) logger.WithName("hasErrCondOnSubResource") if err != nil { @@ -229,7 +230,7 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) hasErrCondOnSubResource(ctx co return nil } -func (r *RateLimitPolicyEnforcedStatusReconciler) setCondition(ctx context.Context, p *kuadrantv1beta2.RateLimitPolicy, conditions *[]metav1.Condition, cond metav1.Condition) error { +func (r *RateLimitPolicyEnforcedStatusReconciler) setCondition(ctx context.Context, p *kuadrantv1beta3.RateLimitPolicy, conditions *[]metav1.Condition, cond metav1.Condition) error { logger, err := logr.FromContext(ctx) logger.WithName("setCondition") if err != nil { @@ -301,7 +302,7 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) SetupWithManager(mgr ctrl.Mana handler.EnqueueRequestsFromMapFunc(httpRouteToParentGatewaysEventMapper.Map), ). Watches( - &kuadrantv1beta2.RateLimitPolicy{}, + &kuadrantv1beta3.RateLimitPolicy{}, handler.EnqueueRequestsFromMapFunc(policyToParentGatewaysEventMapper.Map), builder.WithPredicates(policyStatusChangedPredicate), ). diff --git a/controllers/ratelimitpolicy_limits.go b/controllers/ratelimitpolicy_limits.go index 2a704309f..442df9b87 100644 --- a/controllers/ratelimitpolicy_limits.go +++ b/controllers/ratelimitpolicy_limits.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/common" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" @@ -21,7 +21,7 @@ import ( "github.com/kuadrant/kuadrant-operator/pkg/rlptools" ) -func (r *RateLimitPolicyReconciler) reconcileLimits(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy) error { +func (r *RateLimitPolicyReconciler) reconcileLimits(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy) error { policies, err := r.getPolicies(ctx) if err != nil { return err @@ -33,7 +33,7 @@ func (r *RateLimitPolicyReconciler) reconcileLimits(ctx context.Context, rlp *ku return r.reconcileLimitador(ctx, rlp, topology) } -func (r *RateLimitPolicyReconciler) deleteLimits(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy) error { +func (r *RateLimitPolicyReconciler) deleteLimits(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy) error { policies, err := r.getPolicies(ctx) if err != nil { return err @@ -48,7 +48,7 @@ func (r *RateLimitPolicyReconciler) deleteLimits(ctx context.Context, rlp *kuadr return r.reconcileLimitador(ctx, rlp, topology) } -func (r *RateLimitPolicyReconciler) reconcileLimitador(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, topology *kuadrantgatewayapi.Topology) error { +func (r *RateLimitPolicyReconciler) reconcileLimitador(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy, topology *kuadrantgatewayapi.Topology) error { logger, _ := logr.FromContext(ctx) logger = logger.WithName("reconcileLimitador") @@ -76,7 +76,7 @@ func (r *RateLimitPolicyReconciler) reconcileLimitador(ctx context.Context, rlp return nil } -func GetLimitador(ctx context.Context, k8sclient client.Client, rlp *kuadrantv1beta2.RateLimitPolicy) (*limitadorv1alpha1.Limitador, error) { +func GetLimitador(ctx context.Context, k8sclient client.Client, rlp *kuadrantv1beta3.RateLimitPolicy) (*limitadorv1alpha1.Limitador, error) { logger, _ := logr.FromContext(ctx) logger.V(1).Info("get kuadrant namespace") @@ -110,14 +110,14 @@ func GetLimitador(ctx context.Context, k8sclient client.Client, rlp *kuadrantv1b func (r *RateLimitPolicyReconciler) getPolicies(ctx context.Context) ([]kuadrantgatewayapi.Policy, error) { logger, _ := logr.FromContext(ctx) - rlpList := &kuadrantv1beta2.RateLimitPolicyList{} + rlpList := &kuadrantv1beta3.RateLimitPolicyList{} err := r.Client().List(ctx, rlpList) logger.V(1).Info("topology: list rate limit policies", "#RLPS", len(rlpList.Items), "err", err) if err != nil { return nil, err } - policies := utils.Map(rlpList.Items, func(p kuadrantv1beta2.RateLimitPolicy) kuadrantgatewayapi.Policy { return &p }) + policies := utils.Map(rlpList.Items, func(p kuadrantv1beta3.RateLimitPolicy) kuadrantgatewayapi.Policy { return &p }) return policies, nil } @@ -189,7 +189,7 @@ func (r *RateLimitPolicyReconciler) buildRateLimitIndex(ctx context.Context, top logger.Error(fmt.Errorf("unexpected duplicate rate limit policy key found"), "failed do add rate limit policy to index", "RateLimitPolicy", rlpKey.String(), "Gateway", gatewayKey) continue } - rlp := policy.(*kuadrantv1beta2.RateLimitPolicy) + rlp := policy.(*kuadrantv1beta3.RateLimitPolicy) rateLimitIndex.Set(key, rlptools.LimitadorRateLimitsFromRLP(rlp)) } } diff --git a/controllers/ratelimitpolicy_status.go b/controllers/ratelimitpolicy_status.go index 980906a8e..6ece9605b 100644 --- a/controllers/ratelimitpolicy_status.go +++ b/controllers/ratelimitpolicy_status.go @@ -12,18 +12,18 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" ) -func (r *RateLimitPolicyReconciler) reconcileStatus(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, specErr error) (ctrl.Result, error) { +func (r *RateLimitPolicyReconciler) reconcileStatus(ctx context.Context, rlp *kuadrantv1beta3.RateLimitPolicy, specErr error) (ctrl.Result, error) { logger, _ := logr.FromContext(ctx) newStatus := r.calculateStatus(rlp, specErr) if err := r.ReconcileResourceStatus( ctx, client.ObjectKeyFromObject(rlp), - &kuadrantv1beta2.RateLimitPolicy{}, - kuadrantv1beta2.RateLimitPolicyStatusMutator(newStatus, logger), + &kuadrantv1beta3.RateLimitPolicy{}, + kuadrantv1beta3.RateLimitPolicyStatusMutator(newStatus, logger), ); err != nil { // Ignore conflicts, resource might just be outdated. if apierrors.IsConflict(err) { @@ -37,8 +37,8 @@ func (r *RateLimitPolicyReconciler) reconcileStatus(ctx context.Context, rlp *ku return ctrl.Result{}, nil } -func (r *RateLimitPolicyReconciler) calculateStatus(rlp *kuadrantv1beta2.RateLimitPolicy, specErr error) *kuadrantv1beta2.RateLimitPolicyStatus { - newStatus := &kuadrantv1beta2.RateLimitPolicyStatus{ +func (r *RateLimitPolicyReconciler) calculateStatus(rlp *kuadrantv1beta3.RateLimitPolicy, specErr error) *kuadrantv1beta3.RateLimitPolicyStatus { + newStatus := &kuadrantv1beta3.RateLimitPolicyStatus{ // Copy initial conditions. Otherwise, status will always be updated Conditions: slices.Clone(rlp.Status.Conditions), } diff --git a/controllers/state_of_the_world.go b/controllers/state_of_the_world.go index 563db511d..c18b64cdf 100644 --- a/controllers/state_of_the_world.go +++ b/controllers/state_of_the_world.go @@ -20,6 +20,7 @@ import ( kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1" kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" ) @@ -42,13 +43,13 @@ func NewPolicyMachineryController(manager ctrlruntime.Manager, client *dynamic.D controller.WithRunnable("dnspolicy watcher", controller.Watch(&kuadrantv1alpha1.DNSPolicy{}, kuadrantv1alpha1.DNSPoliciesResource, metav1.NamespaceAll)), controller.WithRunnable("tlspolicy watcher", controller.Watch(&kuadrantv1alpha1.TLSPolicy{}, kuadrantv1alpha1.TLSPoliciesResource, metav1.NamespaceAll)), controller.WithRunnable("authpolicy watcher", controller.Watch(&kuadrantv1beta2.AuthPolicy{}, kuadrantv1beta2.AuthPoliciesResource, metav1.NamespaceAll)), - controller.WithRunnable("ratelimitpolicy watcher", controller.Watch(&kuadrantv1beta2.RateLimitPolicy{}, kuadrantv1beta2.RateLimitPoliciesResource, metav1.NamespaceAll)), + controller.WithRunnable("ratelimitpolicy watcher", controller.Watch(&kuadrantv1beta3.RateLimitPolicy{}, kuadrantv1beta3.RateLimitPoliciesResource, metav1.NamespaceAll)), controller.WithRunnable("topology configmap watcher", controller.Watch(&corev1.ConfigMap{}, controller.ConfigMapsResource, operatorNamespace, controller.FilterResourcesByLabel[*corev1.ConfigMap](fmt.Sprintf("%s=true", kuadrant.TopologyLabel)))), controller.WithPolicyKinds( kuadrantv1alpha1.DNSPolicyKind, kuadrantv1alpha1.TLSPolicyKind, kuadrantv1beta2.AuthPolicyKind, - kuadrantv1beta2.RateLimitPolicyKind, + kuadrantv1beta3.RateLimitPolicyKind, ), controller.WithObjectKinds( kuadrantv1beta1.KuadrantKind, diff --git a/controllers/target_status_controller.go b/controllers/target_status_controller.go index 4e65693c9..799a73131 100644 --- a/controllers/target_status_controller.go +++ b/controllers/target_status_controller.go @@ -40,6 +40,7 @@ import ( kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/library/fieldindexers" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" @@ -83,7 +84,7 @@ func (r *TargetStatusReconciler) reconcileResources(ctx context.Context, gw *gat &kuadrantv1beta2.AuthPolicy{TypeMeta: ctrl.TypeMeta{Kind: "AuthPolicy"}}: &kuadrantv1beta2.AuthPolicyList{}, &kuadrantv1alpha1.DNSPolicy{TypeMeta: ctrl.TypeMeta{Kind: "DNSPolicy"}}: &kuadrantv1alpha1.DNSPolicyList{}, &kuadrantv1alpha1.TLSPolicy{TypeMeta: ctrl.TypeMeta{Kind: "TLSPolicy"}}: &kuadrantv1alpha1.TLSPolicyList{}, - &kuadrantv1beta2.RateLimitPolicy{TypeMeta: ctrl.TypeMeta{Kind: "RateLimitPolicy"}}: &kuadrantv1beta2.RateLimitPolicyList{}, + &kuadrantv1beta3.RateLimitPolicy{TypeMeta: ctrl.TypeMeta{Kind: "RateLimitPolicy"}}: &kuadrantv1beta3.RateLimitPolicyList{}, } var errs error @@ -387,7 +388,7 @@ func (r *TargetStatusReconciler) SetupWithManager(mgr ctrl.Manager) error { builder.WithPredicates(policyStatusChangedPredicate), ). Watches( - &kuadrantv1beta2.RateLimitPolicy{}, + &kuadrantv1beta3.RateLimitPolicy{}, handler.EnqueueRequestsFromMapFunc(policyToParentGatewaysEventMapper.Map), builder.WithPredicates(policyStatusChangedPredicate), ). diff --git a/pkg/rlptools/overrides.go b/pkg/rlptools/overrides.go index 5dc47fb3a..f361ef16f 100644 --- a/pkg/rlptools/overrides.go +++ b/pkg/rlptools/overrides.go @@ -7,7 +7,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" ) @@ -22,9 +22,9 @@ func ApplyOverrides(topology *kuadrantgatewayapi.Topology, gateway *gatewayapiv1 return topology, nil } - overridePolicies := lo.FilterMap(gatewayNode.AttachedPolicies(), func(pNode kuadrantgatewayapi.PolicyNode, _ int) (*kuadrantv1beta2.RateLimitPolicy, bool) { + overridePolicies := lo.FilterMap(gatewayNode.AttachedPolicies(), func(pNode kuadrantgatewayapi.PolicyNode, _ int) (*kuadrantv1beta3.RateLimitPolicy, bool) { policy := pNode.Policy - rlp, ok := policy.(*kuadrantv1beta2.RateLimitPolicy) + rlp, ok := policy.(*kuadrantv1beta3.RateLimitPolicy) if !ok || rlp.Spec.Overrides == nil { return nil, false } @@ -35,7 +35,7 @@ func ApplyOverrides(topology *kuadrantgatewayapi.Topology, gateway *gatewayapiv1 return topology, nil } - overriddenPolicies := lo.Map(overridePolicies, func(p *kuadrantv1beta2.RateLimitPolicy, _ int) kuadrantgatewayapi.Policy { return p }) + overriddenPolicies := lo.Map(overridePolicies, func(p *kuadrantv1beta3.RateLimitPolicy, _ int) kuadrantgatewayapi.Policy { return p }) for _, route := range topology.Routes() { if !slices.Contains(kuadrantgatewayapi.GetRouteAcceptedGatewayParentKeys(route.HTTPRoute), client.ObjectKeyFromObject(gateway)) { @@ -45,7 +45,7 @@ func ApplyOverrides(topology *kuadrantgatewayapi.Topology, gateway *gatewayapiv1 } for _, policy := range route.AttachedPolicies() { - overriddenPolicy := policy.DeepCopyObject().(*kuadrantv1beta2.RateLimitPolicy) + overriddenPolicy := policy.DeepCopyObject().(*kuadrantv1beta3.RateLimitPolicy) overriddenPolicy.Spec.CommonSpec().Limits = overridePolicies[0].Spec.Overrides.Limits overriddenPolicies = append(overriddenPolicies, overriddenPolicy) } diff --git a/pkg/rlptools/utils.go b/pkg/rlptools/utils.go index a8ca94d92..f5472e695 100644 --- a/pkg/rlptools/utils.go +++ b/pkg/rlptools/utils.go @@ -6,25 +6,25 @@ import ( limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" "sigs.k8s.io/controller-runtime/pkg/client" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" "github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm" ) -func LimitsNameFromRLP(rlp *kuadrantv1beta2.RateLimitPolicy) string { +func LimitsNameFromRLP(rlp *kuadrantv1beta3.RateLimitPolicy) string { return wasm.LimitsNamespaceFromRLP(rlp) } -var timeUnitMap = map[kuadrantv1beta2.TimeUnit]int{ - kuadrantv1beta2.TimeUnit("second"): 1, - kuadrantv1beta2.TimeUnit("minute"): 60, - kuadrantv1beta2.TimeUnit("hour"): 60 * 60, - kuadrantv1beta2.TimeUnit("day"): 60 * 60 * 24, +var timeUnitMap = map[kuadrantv1beta3.TimeUnit]int{ + kuadrantv1beta3.TimeUnit("second"): 1, + kuadrantv1beta3.TimeUnit("minute"): 60, + kuadrantv1beta3.TimeUnit("hour"): 60 * 60, + kuadrantv1beta3.TimeUnit("day"): 60 * 60 * 24, } // LimitadorRateLimitsFromRLP converts rate limits from a Kuadrant RateLimitPolicy into a list of Limitador rate limit // objects -func LimitadorRateLimitsFromRLP(rlp *kuadrantv1beta2.RateLimitPolicy) []limitadorv1alpha1.RateLimit { +func LimitadorRateLimitsFromRLP(rlp *kuadrantv1beta3.RateLimitPolicy) []limitadorv1alpha1.RateLimit { limitsNamespace := wasm.LimitsNamespaceFromRLP(rlp) rlpKey := client.ObjectKeyFromObject(rlp) @@ -48,7 +48,7 @@ func LimitadorRateLimitsFromRLP(rlp *kuadrantv1beta2.RateLimitPolicy) []limitado // rateToSeconds converts from RLP Rate API (limit, duration and unit) // to Limitador's Limit format (maxValue, Seconds) -func rateToSeconds(rate kuadrantv1beta2.Rate) (maxValue int, seconds int) { +func rateToSeconds(rate kuadrantv1beta3.Rate) (maxValue int, seconds int) { maxValue = rate.Limit seconds = 0 diff --git a/pkg/rlptools/wasm/types.go b/pkg/rlptools/wasm/types.go index 2e470e6a5..d079f2e06 100644 --- a/pkg/rlptools/wasm/types.go +++ b/pkg/rlptools/wasm/types.go @@ -8,21 +8,21 @@ import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" ) var ( PathMatchTypeMap = map[gatewayapiv1.PathMatchType]PatternOperator{ - gatewayapiv1.PathMatchExact: PatternOperator(kuadrantv1beta2.EqualOperator), - gatewayapiv1.PathMatchPathPrefix: PatternOperator(kuadrantv1beta2.StartsWithOperator), - gatewayapiv1.PathMatchRegularExpression: PatternOperator(kuadrantv1beta2.MatchesOperator), + gatewayapiv1.PathMatchExact: PatternOperator(kuadrantv1beta3.EqualOperator), + gatewayapiv1.PathMatchPathPrefix: PatternOperator(kuadrantv1beta3.StartsWithOperator), + gatewayapiv1.PathMatchRegularExpression: PatternOperator(kuadrantv1beta3.MatchesOperator), } ) type SelectorSpec struct { // Selector of an attribute from the contextual properties provided by kuadrant // during request and connection processing - Selector kuadrantv1beta2.ContextSelector `json:"selector"` + Selector kuadrantv1beta3.ContextSelector `json:"selector"` // If not set it defaults to `selector` field value as the descriptor key. // +optional @@ -49,12 +49,12 @@ type DataItem struct { Selector *SelectorSpec `json:"selector,omitempty"` } -type PatternOperator kuadrantv1beta2.WhenConditionOperator +type PatternOperator kuadrantv1beta3.WhenConditionOperator type PatternExpression struct { // Selector of an attribute from the contextual properties provided by kuadrant // during request and connection processing - Selector kuadrantv1beta2.ContextSelector `json:"selector"` + Selector kuadrantv1beta3.ContextSelector `json:"selector"` // The binary operator to be applied to the content fetched from context, for comparison with "value". // Possible values are: "eq" (equal to), "neq" (not equal to), "incl" (includes; for arrays), "excl" (excludes; for arrays), "matches" (regex) diff --git a/pkg/rlptools/wasm/utils.go b/pkg/rlptools/wasm/utils.go index afb192303..610f4523b 100644 --- a/pkg/rlptools/wasm/utils.go +++ b/pkg/rlptools/wasm/utils.go @@ -18,7 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" "github.com/kuadrant/kuadrant-operator/pkg/common" kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" @@ -32,14 +32,14 @@ var ( WASMFilterImageURL = env.GetString("RELATED_IMAGE_WASMSHIM", "oci://quay.io/kuadrant/wasm-shim:latest") ) -func LimitsNamespaceFromRLP(rlp *kuadrantv1beta2.RateLimitPolicy) string { +func LimitsNamespaceFromRLP(rlp *kuadrantv1beta3.RateLimitPolicy) string { return fmt.Sprintf("%s/%s", rlp.GetNamespace(), rlp.GetName()) } // Rules computes WASM rules from the policy and the targeted route. // It returns an empty list of wasm rules if the policy specifies no limits or if all limits specified in the policy // fail to match any route rule according to the limits route selectors. -func Rules(rlp *kuadrantv1beta2.RateLimitPolicy, route *gatewayapiv1.HTTPRoute) []Rule { +func Rules(rlp *kuadrantv1beta3.RateLimitPolicy, route *gatewayapiv1.HTTPRoute) []Rule { rules := make([]Rule, 0) if rlp == nil { return rules @@ -84,7 +84,7 @@ func LimitNameToLimitadorIdentifier(rlpKey types.NamespacedName, uniqueLimitName return identifier } -func ruleFromLimit(limitIdentifier string, limit *kuadrantv1beta2.Limit, route *gatewayapiv1.HTTPRoute) (Rule, error) { +func ruleFromLimit(limitIdentifier string, limit *kuadrantv1beta3.Limit, route *gatewayapiv1.HTTPRoute) (Rule, error) { rule := Rule{} conditions, err := conditionsFromLimit(limit, route) @@ -101,7 +101,7 @@ func ruleFromLimit(limitIdentifier string, limit *kuadrantv1beta2.Limit, route * return rule, nil } -func conditionsFromLimit(limit *kuadrantv1beta2.Limit, route *gatewayapiv1.HTTPRoute) ([]Condition, error) { +func conditionsFromLimit(limit *kuadrantv1beta3.Limit, route *gatewayapiv1.HTTPRoute) ([]Condition, error) { if limit == nil { return nil, errors.New("limit should not be nil") } @@ -122,7 +122,7 @@ func conditionsFromLimit(limit *kuadrantv1beta2.Limit, route *gatewayapiv1.HTTPR } } else { // build conditions from all rules if no route selectors are defined - hostnamesForConditions := (&kuadrantv1beta2.RouteSelector{}).HostnamesForConditions(route) + hostnamesForConditions := (&kuadrantv1beta3.RouteSelector{}).HostnamesForConditions(route) for _, rule := range route.Spec.Rules { routeConditions = append(routeConditions, conditionsFromRule(rule, hostnamesForConditions)...) } @@ -221,7 +221,7 @@ func patternExpresionsFromMatch(match gatewayapiv1.HTTPRouteMatch) []PatternExpr func patternExpresionFromPathMatch(pathMatch gatewayapiv1.HTTPPathMatch) PatternExpression { var ( - operator = PatternOperator(kuadrantv1beta2.StartsWithOperator) // default value + operator = PatternOperator(kuadrantv1beta3.StartsWithOperator) // default value value = "/" // default value ) @@ -245,7 +245,7 @@ func patternExpresionFromPathMatch(pathMatch gatewayapiv1.HTTPPathMatch) Pattern func patternExpresionFromMethod(method gatewayapiv1.HTTPMethod) PatternExpression { return PatternExpression{ Selector: "request.method", - Operator: PatternOperator(kuadrantv1beta2.EqualOperator), + Operator: PatternOperator(kuadrantv1beta3.EqualOperator), Value: string(method), } } @@ -255,8 +255,8 @@ func patternExpresionFromHeader(headerMatch gatewayapiv1.HTTPHeaderMatch) Patter // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPHeaderMatch return PatternExpression{ - Selector: kuadrantv1beta2.ContextSelector(fmt.Sprintf("request.headers.%s", headerMatch.Name)), - Operator: PatternOperator(kuadrantv1beta2.EqualOperator), + Selector: kuadrantv1beta3.ContextSelector(fmt.Sprintf("request.headers.%s", headerMatch.Name)), + Operator: PatternOperator(kuadrantv1beta3.EqualOperator), Value: headerMatch.Value, } } @@ -275,7 +275,7 @@ func patternExpresionFromHostname(hostname gatewayapiv1.Hostname) PatternExpress } } -func patternExpresionFromWhen(when kuadrantv1beta2.WhenCondition) PatternExpression { +func patternExpresionFromWhen(when kuadrantv1beta3.WhenCondition) PatternExpression { return PatternExpression{ Selector: when.Selector, Operator: PatternOperator(when.Operator), @@ -283,7 +283,7 @@ func patternExpresionFromWhen(when kuadrantv1beta2.WhenCondition) PatternExpress } } -func dataFromLimit(limitIdentifier string, limit *kuadrantv1beta2.Limit) (data []DataItem) { +func dataFromLimit(limitIdentifier string, limit *kuadrantv1beta3.Limit) (data []DataItem) { if limit == nil { return } @@ -298,7 +298,7 @@ func dataFromLimit(limitIdentifier string, limit *kuadrantv1beta2.Limit) (data [ return data } -func routeFromRLP(ctx context.Context, t *kuadrantgatewayapi.TopologyIndexes, rlp *kuadrantv1beta2.RateLimitPolicy, gw *gatewayapiv1.Gateway) (*gatewayapiv1.HTTPRoute, error) { +func routeFromRLP(ctx context.Context, t *kuadrantgatewayapi.TopologyIndexes, rlp *kuadrantv1beta3.RateLimitPolicy, gw *gatewayapiv1.Gateway) (*gatewayapiv1.HTTPRoute, error) { logger, err := logr.FromContext(ctx) if err != nil { return nil, err @@ -337,7 +337,7 @@ func routeFromRLP(ctx context.Context, t *kuadrantgatewayapi.TopologyIndexes, rl return route, nil } -func wasmRateLimitPolicy(ctx context.Context, t *kuadrantgatewayapi.TopologyIndexes, rlp *kuadrantv1beta2.RateLimitPolicy, gw *gatewayapiv1.Gateway) (*RateLimitPolicy, error) { +func wasmRateLimitPolicy(ctx context.Context, t *kuadrantgatewayapi.TopologyIndexes, rlp *kuadrantv1beta3.RateLimitPolicy, gw *gatewayapiv1.Gateway) (*RateLimitPolicy, error) { route, err := routeFromRLP(ctx, t, rlp, gw) if err != nil { return nil, err @@ -407,7 +407,7 @@ func ConfigForGateway( } for _, policy := range rateLimitPolicies { - rlp := policy.(*kuadrantv1beta2.RateLimitPolicy) + rlp := policy.(*kuadrantv1beta3.RateLimitPolicy) wasmRLP, err := wasmRateLimitPolicy(ctx, topologyIndex, rlp, gw) if err != nil { return nil, err