@@ -21,13 +21,13 @@ 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
31
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
33
"k8s.io/apimachinery/pkg/runtime"
@@ -43,8 +43,16 @@ import (
43
43
)
44
44
45
45
const (
46
- kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
47
- extAuthorizerName = "kuadrant-authorization"
46
+ kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
47
+ extAuthorizerName = "kuadrant-authorization"
48
+ envLimitadorNamespace = "LIMITADOR_NAMESPACE"
49
+ envLimitadorName = "LIMITADOR_NAME"
50
+ envLimitadorGrpcPort = "LIMITADOR_GRPC_PORT"
51
+ )
52
+
53
+ var (
54
+ limitadorName = common .FetchEnv (envLimitadorName , "limitador" )
55
+ limitadorGrpcPort = common .FetchEnv (envLimitadorGrpcPort , "8081" )
48
56
)
49
57
50
58
// KuadrantReconciler reconciles a Kuadrant object
@@ -341,7 +349,7 @@ func (r *KuadrantReconciler) reconcileLimitador(ctx context.Context, kObj *kuadr
341
349
APIVersion : "limitador.kuadrant.io/v1alpha1" ,
342
350
},
343
351
ObjectMeta : metav1.ObjectMeta {
344
- Name : "limitador" ,
352
+ Name : limitadorName ,
345
353
Namespace : kObj .Namespace ,
346
354
},
347
355
Spec : limitadorv1alpha1.LimitadorSpec {},
@@ -386,14 +394,27 @@ func (r *KuadrantReconciler) createOnlyInKuadrantNSCb(ctx context.Context, kObj
386
394
return err
387
395
}
388
396
389
- k8sObjKind := k8sObj .DeepCopyObject ().GetObjectKind ()
397
+ var newObj client.Object
398
+ newObj = k8sObj
399
+
400
+ switch obj := k8sObj .(type ) {
401
+ case * appsv1.Deployment : // If it's a Deployment obj, it adds the required env vars
402
+ obj .Spec .Template .Spec .Containers [0 ].Env = []v1.EnvVar {
403
+ {Name : envLimitadorNamespace , Value : kObj .Namespace },
404
+ {Name : envLimitadorName , Value : limitadorName },
405
+ {Name : envLimitadorGrpcPort , Value : limitadorGrpcPort },
406
+ }
407
+ newObj = obj
408
+ default :
409
+ }
410
+ err = r .Client ().Create (ctx , newObj )
390
411
391
- err = r . Client ().Create ( ctx , k8sObj )
392
- logger .V (1 ).Info ("create resource" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , k8sObj .GetName (), "error" , err )
412
+ k8sObjKind := newObj . DeepCopyObject ().GetObjectKind ( )
413
+ logger .V (1 ).Info ("create resource" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , newObj .GetName (), "error" , err )
393
414
if err != nil {
394
415
if apierrors .IsAlreadyExists (err ) {
395
416
// Omit error
396
- logger .Info ("Already exists" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , k8sObj .GetName ())
417
+ logger .Info ("Already exists" , "GKV" , k8sObjKind .GroupVersionKind (), "name" , newObj .GetName ())
397
418
} else {
398
419
return err
399
420
}
0 commit comments