@@ -21,13 +21,14 @@ import (
21
21
"encoding/json"
22
22
"errors"
23
23
"fmt"
24
-
25
24
"github.com/go-logr/logr"
26
25
authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1"
27
26
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
28
27
istioapiv1alpha1 "istio.io/api/operator/v1alpha1"
29
28
iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1"
30
29
appsv1 "k8s.io/api/apps/v1"
30
+ v1 "k8s.io/api/core/v1"
31
+ rbacv1 "k8s.io/api/rbac/v1"
31
32
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
34
"k8s.io/apimachinery/pkg/runtime"
@@ -43,8 +44,14 @@ import (
43
44
)
44
45
45
46
const (
46
- kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
47
- extAuthorizerName = "kuadrant-authorization"
47
+ kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
48
+ extAuthorizerName = "kuadrant-authorization"
49
+ envLimitadorNamespace = "LIMITADOR_NAMESPACE"
50
+ envLimitadorName = "LIMITADOR_NAME"
51
+ )
52
+
53
+ var (
54
+ limitadorName = common .FetchEnv (envLimitadorName , "limitador" )
48
55
)
49
56
50
57
// KuadrantReconciler reconciles a Kuadrant object
@@ -344,7 +351,7 @@ func (r *KuadrantReconciler) reconcileLimitador(ctx context.Context, kObj *kuadr
344
351
APIVersion : "limitador.kuadrant.io/v1alpha1" ,
345
352
},
346
353
ObjectMeta : metav1.ObjectMeta {
347
- Name : "limitador" ,
354
+ Name : limitadorName ,
348
355
Namespace : kObj .Namespace ,
349
356
},
350
357
Spec : limitadorv1alpha1.LimitadorSpec {},
@@ -389,14 +396,47 @@ func (r *KuadrantReconciler) createOnlyInKuadrantNSCb(ctx context.Context, kObj
389
396
return err
390
397
}
391
398
392
- k8sObjKind := k8sObj .DeepCopyObject ().GetObjectKind ()
399
+ var newObj client.Object
400
+ newObj = k8sObj
401
+
402
+ switch obj := k8sObj .(type ) {
403
+ case * appsv1.Deployment : // If it's a Deployment obj, it adds the required env vars
404
+ obj .Spec .Template .Spec .Containers [0 ].Env = append (
405
+ obj .Spec .Template .Spec .Containers [0 ].Env ,
406
+ v1.EnvVar {Name : envLimitadorNamespace , Value : kObj .Namespace },
407
+ v1.EnvVar {Name : envLimitadorName , Value : limitadorName },
408
+ )
409
+ newObj = obj
410
+ // TODO: DRY the following 2 case switches
411
+ case * rbacv1.RoleBinding :
412
+ if obj .Name == "kuadrant-leader-election-rolebinding" {
413
+ for i , subject := range obj .Subjects {
414
+ if subject .Name == "kuadrant-controller-manager" {
415
+ obj .Subjects [i ].Namespace = kObj .Namespace
416
+ }
417
+ }
418
+ }
419
+ newObj = obj
420
+ case * rbacv1.ClusterRoleBinding :
421
+ if obj .Name == "kuadrant-manager-rolebinding" {
422
+ for i , subject := range obj .Subjects {
423
+ if subject .Name == "kuadrant-controller-manager" {
424
+ obj .Subjects [i ].Namespace = kObj .Namespace
425
+ }
426
+ }
427
+ }
428
+ newObj = obj
429
+ default :
430
+ }
431
+ newObjCloned := newObj .DeepCopyObject ()
432
+ err = r .Client ().Create (ctx , newObj )
393
433
394
- err = r . Client (). Create ( ctx , k8sObj )
395
- logger .V (1 ).Info ("create resource" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , k8sObj .GetName (), "error" , err )
434
+ k8sObjKind := newObjCloned . GetObjectKind ( )
435
+ logger .V (1 ).Info ("create resource" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , newObj .GetName (), "error" , err )
396
436
if err != nil {
397
437
if apierrors .IsAlreadyExists (err ) {
398
438
// Omit error
399
- logger .Info ("Already exists" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , k8sObj .GetName ())
439
+ logger .Info ("Already exists" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , newObj .GetName ())
400
440
} else {
401
441
return err
402
442
}
0 commit comments