Skip to content

Commit

Permalink
[controller] Propagating Limitador's env vars
Browse files Browse the repository at this point in the history
* limitador namespace
* limitador service name
* limitador service grpc port

* Using keyed values
  • Loading branch information
didierofrivia committed Jun 1, 2022
1 parent cd03aa9 commit 9bcba88
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"encoding/json"
"errors"
"fmt"

"github.com/go-logr/logr"
authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1"
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
istioapiv1alpha1 "istio.io/api/operator/v1alpha1"
iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -43,8 +43,15 @@ import (
)

const (
kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
extAuthorizerName = "kuadrant-authorization"
kuadrantFinalizer = "kuadrant.kuadrant.io/finalizer"
extAuthorizerName = "kuadrant-authorization"
envLimitadorServiceName = "LIMITADOR_SERVICE_NAME"
envLimitadorServiceGrpcPort = "LIMITADOR_SERVICE_GRPC_PORT"
)

var (
limitadorServiceName = common.FetchEnv(envLimitadorServiceName, "limitador")
limitadorServiceGrpcPort = common.FetchEnv(envLimitadorServiceGrpcPort, "8081")
)

// KuadrantReconciler reconciles a Kuadrant object
Expand Down Expand Up @@ -386,9 +393,19 @@ func (r *KuadrantReconciler) createOnlyInKuadrantNSCb(ctx context.Context, kObj
return err
}

switch obj := k8sObj.(type) {
case *appsv1.Deployment: // If it's a Deployment obj, it adds the required env vars
obj.Spec.Template.Spec.Containers[0].Env = []v1.EnvVar{
{Name: "LIMITADOR_NAMESPACE", Value: kObj.Namespace, ValueFrom: &v1.EnvVarSource{}},
{Name: envLimitadorServiceName, Value: limitadorServiceName, ValueFrom: &v1.EnvVarSource{}},
{Name: envLimitadorServiceGrpcPort, Value: limitadorServiceGrpcPort, ValueFrom: &v1.EnvVarSource{}},
}
err = r.Client().Create(ctx, obj)
default:
err = r.Client().Create(ctx, k8sObj)
}
k8sObjKind := k8sObj.DeepCopyObject().GetObjectKind()

err = r.Client().Create(ctx, k8sObj)
logger.V(1).Info("create resource", "GKV", k8sObjKind.GroupVersionKind(), "name", k8sObj.GetName(), "error", err)
if err != nil {
if apierrors.IsAlreadyExists(err) {
Expand Down

0 comments on commit 9bcba88

Please sign in to comment.