From 66ef250c2750ac23a9b27625f2ca14eb8472509f Mon Sep 17 00:00:00 2001 From: KevFan Date: Fri, 8 Nov 2024 16:34:15 +0000 Subject: [PATCH] feat: report missing Limitator/Authorino Operator to kuadrant status Signed-off-by: KevFan --- controllers/kuadrant_status_updater.go | 23 +++++++++++++++----- controllers/state_of_the_world.go | 15 ++++++++++--- tests/gatewayapi/kuadrant_controller_test.go | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/controllers/kuadrant_status_updater.go b/controllers/kuadrant_status_updater.go index 4f96068b6..3a0803d8f 100644 --- a/controllers/kuadrant_status_updater.go +++ b/controllers/kuadrant_status_updater.go @@ -7,6 +7,7 @@ import ( "sync" "github.com/go-logr/logr" + limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" "github.com/kuadrant/policy-machinery/controller" "github.com/kuadrant/policy-machinery/machinery" corev1 "k8s.io/api/core/v1" @@ -18,6 +19,7 @@ import ( kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" "github.com/kuadrant/kuadrant-operator/pkg/authorino" + "github.com/kuadrant/kuadrant-operator/pkg/kuadrant" ) const ( @@ -25,12 +27,14 @@ const ( ) type KuadrantStatusUpdater struct { - Client *dynamic.DynamicClient - HasGateway bool + Client *dynamic.DynamicClient + HasGateway bool + isLimitadorOperatorInstalled bool + isAuthorinoOperatorInstalled bool } -func NewKuadrantStatusUpdater(client *dynamic.DynamicClient, isIstioInstalled, isEnvoyGatewayInstalled bool) *KuadrantStatusUpdater { - return &KuadrantStatusUpdater{Client: client, HasGateway: isIstioInstalled || isEnvoyGatewayInstalled} +func NewKuadrantStatusUpdater(client *dynamic.DynamicClient, isIstioInstalled, isEnvoyGatewayInstalled, isLimitadorOperatorInstalled, isAuthorinoOperatorInstalled bool) *KuadrantStatusUpdater { + return &KuadrantStatusUpdater{Client: client, HasGateway: isIstioInstalled || isEnvoyGatewayInstalled, isLimitadorOperatorInstalled: isLimitadorOperatorInstalled, isAuthorinoOperatorInstalled: isAuthorinoOperatorInstalled} } func (r *KuadrantStatusUpdater) Subscription() *controller.Subscription { @@ -120,7 +124,14 @@ func (r *KuadrantStatusUpdater) readyCondition(topology *machinery.Topology, log if !r.HasGateway { cond.Status = metav1.ConditionFalse cond.Reason = "GatewayAPIProviderNotFound" - cond.Message = "GatewayAPI provider not found" + cond.Message = kuadrant.NewErrDependencyNotInstalled("GatewayAPI provider").Error() + return cond + } + + if !r.isLimitadorOperatorInstalled { + cond.Status = metav1.ConditionFalse + cond.Reason = "LimitadorAPIProviderNotFound" + cond.Message = kuadrant.NewErrDependencyNotInstalled("Limitador Operator").Error() return cond } @@ -166,7 +177,7 @@ func checkAuthorinoAvailable(topology *machinery.Topology, logger logr.Logger) * return ptr.To("authorino resoure not in topology") } - readyCondition := authorino.FindAuthorinoStatusCondition(authorinoObj.Status.Conditions, "Ready") + readyCondition := authorino.FindAuthorinoStatusCondition(authorinoObj.Status.Conditions, limitadorv1alpha1.StatusConditionReady) if readyCondition == nil { return ptr.To("Ready condition not found") } diff --git a/controllers/state_of_the_world.go b/controllers/state_of_the_world.go index 7ad6eb577..505834838 100644 --- a/controllers/state_of_the_world.go +++ b/controllers/state_of_the_world.go @@ -396,12 +396,10 @@ func (b *BootOptionsBuilder) Reconciler() controller.ReconcileFunc { mainWorkflow := &controller.Workflow{ Precondition: initWorkflow(b.client).Run, Tasks: []controller.ReconcileFunc{ - NewAuthorinoReconciler(b.client).Subscription().Reconcile, - NewLimitadorReconciler(b.client).Subscription().Reconcile, NewDNSWorkflow(b.client, b.manager.GetScheme(), b.isDNSOperatorInstalled).Run, NewTLSWorkflow(b.client, b.manager.GetScheme(), b.isCertManagerInstalled).Run, NewDataPlanePoliciesWorkflow(b.client, b.isIstioInstalled, b.isEnvoyGatewayInstalled, b.isLimitadorOperatorInstalled, b.isAuthorinoOperatorInstalled).Run, - NewKuadrantStatusUpdater(b.client, b.isIstioInstalled, b.isEnvoyGatewayInstalled).Subscription().Reconcile, + NewKuadrantStatusUpdater(b.client, b.isIstioInstalled, b.isEnvoyGatewayInstalled, b.isLimitadorOperatorInstalled, b.isAuthorinoOperatorInstalled).Subscription().Reconcile, }, Postcondition: finalStepsWorkflow(b.client, b.isIstioInstalled, b.isGatewayAPIInstalled).Run, } @@ -412,6 +410,17 @@ func (b *BootOptionsBuilder) Reconciler() controller.ReconcileFunc { ) } + if b.isLimitadorOperatorInstalled { + mainWorkflow.Tasks = append(mainWorkflow.Tasks, + NewLimitadorReconciler(b.client).Subscription().Reconcile, + ) + } + + if b.isAuthorinoOperatorInstalled { + mainWorkflow.Tasks = append(mainWorkflow.Tasks, + NewAuthorinoReconciler(b.client).Subscription().Reconcile) + } + return mainWorkflow.Run } diff --git a/tests/gatewayapi/kuadrant_controller_test.go b/tests/gatewayapi/kuadrant_controller_test.go index fdf101b13..ec02ddf05 100644 --- a/tests/gatewayapi/kuadrant_controller_test.go +++ b/tests/gatewayapi/kuadrant_controller_test.go @@ -53,7 +53,7 @@ var _ = Describe("Kuadrant controller when gateway provider is missing", func() g.Expect(cond).ToNot(BeNil()) g.Expect(cond.Status).To(Equal(metav1.ConditionFalse)) g.Expect(cond.Reason).To(Equal("GatewayAPIProviderNotFound")) - g.Expect(cond.Message).To(Equal("GatewayAPI provider not found")) + g.Expect(cond.Message).To(Equal("GatewayAPI provider is not installed, please restart pod once dependency has been installed")) }, time.Minute, 15*time.Second).WithContext(ctx).Should(Succeed()) }) })