Skip to content

Commit

Permalink
[controller] Patching the (Cluster)RoleBinding to match Kuadrant NS
Browse files Browse the repository at this point in the history
* It needs some DRY up
* There's no easy way, since obj is type interface when multiple case
  types
  • Loading branch information
didierofrivia committed Jul 29, 2022
1 parent a49a69c commit 52402f4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -406,6 +407,25 @@ func (r *KuadrantReconciler) createOnlyInKuadrantNSCb(ctx context.Context, kObj
v1.EnvVar{Name: envLimitadorName, Value: limitadorName},
)
newObj = obj
// TODO: DRY the following 2 case switches
case *rbacv1.RoleBinding:
if obj.Name == "kuadrant-leader-election-rolebinding" {
for i, subject := range obj.Subjects {
if subject.Name == "kuadrant-controller-manager" {
obj.Subjects[i].Namespace = kObj.Namespace
}
}
}
newObj = obj
case *rbacv1.ClusterRoleBinding:
if obj.Name == "kuadrant-manager-rolebinding" {
for i, subject := range obj.Subjects {
if subject.Name == "kuadrant-controller-manager" {
obj.Subjects[i].Namespace = kObj.Namespace
}
}
}
newObj = obj
default:
}
newObjCloned := newObj.DeepCopyObject()
Expand Down

0 comments on commit 52402f4

Please sign in to comment.