@@ -19,7 +19,6 @@ package apim
19
19
import (
20
20
"context"
21
21
"encoding/json"
22
- "fmt"
23
22
24
23
"github.com/go-logr/logr"
25
24
"github.com/gogo/protobuf/types"
@@ -82,21 +81,25 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl
82
81
}
83
82
84
83
if rlp .GetDeletionTimestamp () != nil && controllerutil .ContainsFinalizer (& rlp , patchesFinalizer ) {
85
- logger .Info ("Removing finalizers " )
84
+ logger .V ( 1 ). Info ("Handling removal of ratelimitpolicy object " )
86
85
if err := r .finalizeEnvoyFilters (ctx , & rlp ); err != nil {
87
86
logger .Error (err , "failed to remove ownerRlp entry from filters patch" )
88
87
return ctrl.Result {}, err
89
88
}
89
+ if err := r .deleteRateLimits (ctx , & rlp ); err != nil {
90
+ logger .Error (err , "failed to delete RateLimt objects" )
91
+ return ctrl.Result {}, err
92
+ }
90
93
controllerutil .RemoveFinalizer (& rlp , patchesFinalizer )
91
- if err := r .BaseReconciler . UpdateResource (ctx , & rlp ); client .IgnoreNotFound (err ) != nil {
94
+ if err := r .UpdateResource (ctx , & rlp ); client .IgnoreNotFound (err ) != nil {
92
95
return ctrl.Result {}, err
93
96
}
94
97
return ctrl.Result {}, nil
95
98
}
96
99
97
100
if ! controllerutil .ContainsFinalizer (& rlp , patchesFinalizer ) {
98
101
controllerutil .AddFinalizer (& rlp , patchesFinalizer )
99
- if err := r .BaseReconciler . UpdateResource (ctx , & rlp ); client .IgnoreNotFound (err ) != nil {
102
+ if err := r .UpdateResource (ctx , & rlp ); client .IgnoreNotFound (err ) != nil {
100
103
return ctrl.Result {Requeue : true }, err
101
104
}
102
105
}
@@ -530,14 +533,17 @@ func virtualHostRateLimitsPatch(vHostName string, rateLimits []*apimv1alpha1.Rat
530
533
}
531
534
532
535
func (r * RateLimitPolicyReconciler ) reconcileLimits (ctx context.Context , rlp * apimv1alpha1.RateLimitPolicy ) error {
533
- logger := r .Logger ()
536
+ logger := logr .FromContext (ctx )
537
+ rlpKey := client .ObjectKeyFromObject (rlp )
534
538
535
539
// create the RateLimit resource
536
540
for i , rlSpec := range rlp .Spec .Limits {
537
541
ratelimitfactory := common.RateLimitFactory {
538
542
Key : client.ObjectKey {
539
- Name : fmt .Sprintf ("%s-limit-%d" , rlp .Name , i + 1 ),
540
- Namespace : rlp .Namespace ,
543
+ Name : limitadorRatelimitsName (rlpKey , i + 1 ),
544
+ // Currently, Limitador Operator (v0.2.0) will configure limitador services with
545
+ // RateLimit CRs created in the same namespace.
546
+ Namespace : common .KuadrantNamespace ,
541
547
},
542
548
Conditions : rlSpec .Conditions ,
543
549
MaxValue : rlSpec .MaxValue ,
@@ -547,11 +553,7 @@ func (r *RateLimitPolicyReconciler) reconcileLimits(ctx context.Context, rlp *ap
547
553
}
548
554
549
555
ratelimit := ratelimitfactory .RateLimit ()
550
- if err := controllerutil .SetOwnerReference (rlp , ratelimit , r .Client ().Scheme ()); err != nil {
551
- logger .Error (err , "failed to add owner ref to RateLimit resource" )
552
- return err
553
- }
554
- err := r .BaseReconciler .ReconcileResource (ctx , & v1alpha1.RateLimit {}, ratelimit , alwaysUpdateRateLimit )
556
+ err := r .ReconcileResource (ctx , & v1alpha1.RateLimit {}, ratelimit , alwaysUpdateRateLimit )
555
557
if err != nil && ! apierrors .IsAlreadyExists (err ) {
556
558
logger .Error (err , "ReconcileResource failed to create/update RateLimit resource" )
557
559
return err
0 commit comments