From 279b063218e83f7dcf93f9e3a4049295bf22a463 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 6 Jun 2024 15:16:02 +0200 Subject: [PATCH] fix rebase issues --- controllers/rate_limiting_istio_wasmplugin_controller.go | 2 +- .../ratelimitpolicy_enforced_status_controller.go | 8 +++++++- pkg/rlptools/topology_index.go | 9 +++++++-- pkg/rlptools/utils.go | 1 - pkg/rlptools/utils_test.go | 1 - pkg/rlptools/wasm/utils.go | 8 ++++---- pkg/rlptools/wasm/utils_test.go | 1 + 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/controllers/rate_limiting_istio_wasmplugin_controller.go b/controllers/rate_limiting_istio_wasmplugin_controller.go index 83bcad478..e4815d153 100644 --- a/controllers/rate_limiting_istio_wasmplugin_controller.go +++ b/controllers/rate_limiting_istio_wasmplugin_controller.go @@ -228,7 +228,7 @@ func (r *RateLimitingIstioWASMPluginReconciler) wasmRateLimitPolicy(ctx context. routeWithEffectiveHostnames := route.DeepCopy() routeWithEffectiveHostnames.Spec.Hostnames = hostnames - rules := rlptools.WasmRules(rlp, routeWithEffectiveHostnames) + rules := wasm.Rules(rlp, routeWithEffectiveHostnames) if len(rules) == 0 { // no need to add the policy if there are no rules; a rlp can return no rules if all its limits fail to match any route rule return nil, nil diff --git a/controllers/ratelimitpolicy_enforced_status_controller.go b/controllers/ratelimitpolicy_enforced_status_controller.go index a8552b81b..457633c04 100644 --- a/controllers/ratelimitpolicy_enforced_status_controller.go +++ b/controllers/ratelimitpolicy_enforced_status_controller.go @@ -24,6 +24,7 @@ import ( gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + "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" "github.com/kuadrant/kuadrant-operator/pkg/library/mappers" @@ -180,7 +181,12 @@ func (r *RateLimitPolicyEnforcedStatusReconciler) buildTopology(ctx context.Cont routeList := &gatewayapiv1.HTTPRouteList{} // Get all the routes having the gateway as parent - err = r.Client().List(ctx, routeList, client.MatchingFields{HTTPRouteGatewayParentField: client.ObjectKeyFromObject(gw).String()}) + err = r.Client().List( + ctx, + routeList, + client.MatchingFields{ + fieldindexers.HTTPRouteGatewayParentField: client.ObjectKeyFromObject(gw).String(), + }) logger.V(1).Info("list routes by gateway", "#routes", len(routeList.Items), "err", err) if err != nil { return nil, err diff --git a/pkg/rlptools/topology_index.go b/pkg/rlptools/topology_index.go index 62bed78ac..03a11da00 100644 --- a/pkg/rlptools/topology_index.go +++ b/pkg/rlptools/topology_index.go @@ -48,7 +48,7 @@ func TopologyIndexesFromGateway(ctx context.Context, cl client.Client, gw *gatew policies := utils.Map(rlpList.Items, func(p kuadrantv1beta2.RateLimitPolicy) kuadrantgatewayapi.Policy { return &p }) - t, err := kuadrantgatewayapi.NewTopology( + topology, err := kuadrantgatewayapi.NewTopology( kuadrantgatewayapi.WithGateways([]*gatewayapiv1.Gateway{gw}), kuadrantgatewayapi.WithRoutes(utils.Map(routeList.Items, ptr.To)), kuadrantgatewayapi.WithPolicies(policies), @@ -58,5 +58,10 @@ func TopologyIndexesFromGateway(ctx context.Context, cl client.Client, gw *gatew return nil, err } - return kuadrantgatewayapi.NewTopologyIndexes(t), nil + overriddenTopology, err := ApplyOverrides(topology, gw) + if err != nil { + return nil, err + } + + return kuadrantgatewayapi.NewTopologyIndexes(overriddenTopology), nil } diff --git a/pkg/rlptools/utils.go b/pkg/rlptools/utils.go index dff73d03c..b90653287 100644 --- a/pkg/rlptools/utils.go +++ b/pkg/rlptools/utils.go @@ -4,7 +4,6 @@ import ( "fmt" limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" - "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" diff --git a/pkg/rlptools/utils_test.go b/pkg/rlptools/utils_test.go index c4af4f0a8..3bb10fbbb 100644 --- a/pkg/rlptools/utils_test.go +++ b/pkg/rlptools/utils_test.go @@ -8,7 +8,6 @@ import ( limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" diff --git a/pkg/rlptools/wasm/utils.go b/pkg/rlptools/wasm/utils.go index e67809478..787c01b83 100644 --- a/pkg/rlptools/wasm/utils.go +++ b/pkg/rlptools/wasm/utils.go @@ -4,13 +4,13 @@ import ( "crypto/sha256" "encoding/hex" "errors" + "fmt" "slices" "strings" "unicode" "github.com/samber/lo" - _struct "google.golang.org/protobuf/types/known/structpb" - istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1" + "k8s.io/apimachinery/pkg/types" "k8s.io/utils/env" "sigs.k8s.io/controller-runtime/pkg/client" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" @@ -55,7 +55,7 @@ func Rules(rlp *kuadrantv1beta2.RateLimitPolicy, route *gatewayapiv1.HTTPRoute) return rules } -func LimitNameToLimitadorIdentifier(uniqueLimitName string) string { +func LimitNameToLimitadorIdentifier(rlpKey types.NamespacedName, uniqueLimitName string) string { identifier := LimitadorRateLimitIdentifierPrefix // sanitize chars that are not allowed in limitador identifiers @@ -68,7 +68,7 @@ func LimitNameToLimitadorIdentifier(uniqueLimitName string) string { } // to avoid breaking the uniqueness of the limit name after sanitization, we add a hash of the original name - hash := sha256.Sum256([]byte(uniqueLimitName)) + hash := sha256.Sum256([]byte(fmt.Sprintf("%s/%s", rlpKey.String(), uniqueLimitName))) identifier += "__" + hex.EncodeToString(hash[:4]) return identifier diff --git a/pkg/rlptools/wasm/utils_test.go b/pkg/rlptools/wasm/utils_test.go index eb39f724e..a6485143a 100644 --- a/pkg/rlptools/wasm/utils_test.go +++ b/pkg/rlptools/wasm/utils_test.go @@ -8,6 +8,7 @@ import ( "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"