Skip to content

Commit 83a6d54

Browse files
move limitador and authorino installed checks to reconciler initialisation
1 parent 39e5d76 commit 83a6d54

File tree

2 files changed

+37
-56
lines changed

2 files changed

+37
-56
lines changed

controllers/mtls_reconciler.go

+35-54
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
kuadrantv1 "github.com/kuadrant/kuadrant-operator/api/v1"
66
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
7-
"github.com/kuadrant/kuadrant-operator/pkg/authorino"
87
"github.com/kuadrant/kuadrant-operator/pkg/istio"
9-
"github.com/kuadrant/kuadrant-operator/pkg/limitador"
108
"github.com/kuadrant/kuadrant-operator/pkg/log"
119
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
1210
"github.com/kuadrant/policy-machinery/controller"
@@ -19,7 +17,6 @@ import (
1917
istiosecurity "istio.io/client-go/pkg/apis/security/v1"
2018
v12 "k8s.io/api/apps/v1"
2119
apiErrors "k8s.io/apimachinery/pkg/api/errors"
22-
"k8s.io/apimachinery/pkg/api/meta"
2320
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2421
"k8s.io/client-go/dynamic"
2522
"k8s.io/utils/ptr"
@@ -37,14 +34,12 @@ func (pa *PeerAuthentication) GetLocator() string {
3734
type MTLSReconciler struct {
3835
*reconcilers.BaseReconciler
3936

40-
Client *dynamic.DynamicClient
41-
restMapper meta.RESTMapper
37+
Client *dynamic.DynamicClient
4238
}
4339

44-
func NewMTLSReconciler(mgr controllerruntime.Manager, client *dynamic.DynamicClient, rm meta.RESTMapper) *MTLSReconciler {
40+
func NewMTLSReconciler(mgr controllerruntime.Manager, client *dynamic.DynamicClient) *MTLSReconciler {
4541
return &MTLSReconciler{
46-
Client: client,
47-
restMapper: rm,
42+
Client: client,
4843
BaseReconciler: reconcilers.NewBaseReconciler(
4944
mgr.GetClient(),
5045
mgr.GetScheme(),
@@ -123,57 +118,43 @@ outer:
123118
return nil
124119
}
125120

126-
installed, err := authorino.IsAuthorinoOperatorInstalled(r.restMapper, logger)
127-
if err != nil || !installed {
128-
logger.Info("authorino is not installed")
129-
return err
130-
}
131-
if installed {
132-
// find an authorino object, then find and update the associated deployment
133-
aobjs := lo.FilterMap(topology.Objects().Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) {
134-
if item.GroupVersionKind().Kind == kuadrantv1beta1.AuthorinoGroupKind.Kind {
135-
return item, true
136-
}
137-
return nil, false
138-
})
139-
// add label to authorino deployment {"sidecar.istio.io/inject":"true"}}}}}
140-
deployment := &v12.Deployment{
141-
ObjectMeta: metav1.ObjectMeta{
142-
// TODO can't be hardcoded, this is just one example
143-
Name: "authorino",
144-
Namespace: aobjs[0].GetNamespace(),
145-
},
121+
// find an authorino object, then find and update the associated deployment
122+
aobjs := lo.FilterMap(topology.Objects().Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) {
123+
if item.GroupVersionKind().Kind == kuadrantv1beta1.AuthorinoGroupKind.Kind {
124+
return item, true
146125
}
147-
deploymentMutators := make([]reconcilers.DeploymentMutateFn, 0)
148-
deploymentMutators = append(deploymentMutators, reconcilers.DeploymentTemplateLabelIstioInjectMutator)
149-
err = r.ReconcileResource(eventCtx, &v12.Deployment{}, deployment, reconcilers.DeploymentMutator(deploymentMutators...))
126+
return nil, false
127+
})
128+
// add label to authorino deployment {"sidecar.istio.io/inject":"true"}}}}}
129+
aDeployment := &v12.Deployment{
130+
ObjectMeta: metav1.ObjectMeta{
131+
// TODO can't be hardcoded, this is just one example
132+
Name: "authorino",
133+
Namespace: aobjs[0].GetNamespace(),
134+
},
150135
}
136+
aDeploymentMutators := make([]reconcilers.DeploymentMutateFn, 0)
137+
aDeploymentMutators = append(aDeploymentMutators, reconcilers.DeploymentTemplateLabelIstioInjectMutator)
138+
err := r.ReconcileResource(eventCtx, &v12.Deployment{}, aDeployment, reconcilers.DeploymentMutator(aDeploymentMutators...))
151139

152-
installed, err = limitador.IsLimitadorOperatorInstalled(r.restMapper, logger)
153-
if err != nil || !installed {
154-
logger.Info("limitador is not installed")
155-
return err
156-
}
157-
if installed {
158-
// find a limitador object, then find and update the associated deployment
159-
lobjs := lo.FilterMap(topology.Objects().Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) {
160-
if item.GroupVersionKind().Kind == kuadrantv1beta1.LimitadorGroupKind.Kind {
161-
return item, true
162-
}
163-
return nil, false
164-
})
165-
// add label to limitador deployment {"sidecar.istio.io/inject":"true"}}}}}
166-
deployment := &v12.Deployment{
167-
ObjectMeta: metav1.ObjectMeta{
168-
// TODO can't be hardcoded, this is just one example
169-
Name: "limitador-limitador",
170-
Namespace: lobjs[0].GetNamespace(),
171-
},
140+
// find a limitador object, then find and update the associated deployment
141+
lobjs := lo.FilterMap(topology.Objects().Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) {
142+
if item.GroupVersionKind().Kind == kuadrantv1beta1.LimitadorGroupKind.Kind {
143+
return item, true
172144
}
173-
deploymentMutators := make([]reconcilers.DeploymentMutateFn, 0)
174-
deploymentMutators = append(deploymentMutators, reconcilers.DeploymentTemplateLabelIstioInjectMutator)
175-
err = r.ReconcileResource(eventCtx, &v12.Deployment{}, deployment, reconcilers.DeploymentMutator(deploymentMutators...))
145+
return nil, false
146+
})
147+
// add label to limitador deployment {"sidecar.istio.io/inject":"true"}}}}}
148+
lDeployment := &v12.Deployment{
149+
ObjectMeta: metav1.ObjectMeta{
150+
// TODO can't be hardcoded, this is just one example
151+
Name: "limitador-limitador",
152+
Namespace: lobjs[0].GetNamespace(),
153+
},
176154
}
155+
lDeploymentMutators := make([]reconcilers.DeploymentMutateFn, 0)
156+
lDeploymentMutators = append(lDeploymentMutators, reconcilers.DeploymentTemplateLabelIstioInjectMutator)
157+
err = r.ReconcileResource(eventCtx, &v12.Deployment{}, lDeployment, reconcilers.DeploymentMutator(lDeploymentMutators...))
177158

178159
valueMap := map[string]interface{}{
179160
"transport_socket": map[string]interface{}{

controllers/state_of_the_world.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ func (b *BootOptionsBuilder) Reconciler() controller.ReconcileFunc {
479479
NewAuthorinoReconciler(b.client).Subscription().Reconcile)
480480
}
481481

482-
if b.isIstioInstalled {
482+
if b.isIstioInstalled && b.isAuthorinoOperatorInstalled && b.isLimitadorOperatorInstalled {
483483
mainWorkflow.Tasks = append(mainWorkflow.Tasks,
484-
NewMTLSReconciler(b.manager, b.client, b.manager.GetRESTMapper()).Subscription().Reconcile,
484+
NewMTLSReconciler(b.manager, b.client).Subscription().Reconcile,
485485
)
486486
}
487487

0 commit comments

Comments
 (0)