Skip to content

Commit

Permalink
feat: report missing Limitator/Authorino Operator to kuadrant status
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Nov 15, 2024
1 parent 31901ee commit 66ef250
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
23 changes: 17 additions & 6 deletions controllers/kuadrant_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,19 +19,22 @@ import (

kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
"github.com/kuadrant/kuadrant-operator/pkg/authorino"
"github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
)

const (
ReadyConditionType string = "Ready"
)

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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
}
Expand Down
15 changes: 12 additions & 3 deletions controllers/state_of_the_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tests/gatewayapi/kuadrant_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
Expand Down

0 comments on commit 66ef250

Please sign in to comment.