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