diff --git a/controllers/auth_policy_status_updater.go b/controllers/auth_policy_status_updater.go index 65b99ef80..b991c8af9 100644 --- a/controllers/auth_policy_status_updater.go +++ b/controllers/auth_policy_status_updater.go @@ -115,6 +115,10 @@ func (r *AuthPolicyStatusUpdater) UpdateStatus(ctx context.Context, _ []controll } func (r *AuthPolicyStatusUpdater) enforcedCondition(policy *kuadrantv1.AuthPolicy, topology *machinery.Topology, state *sync.Map) *metav1.Condition { + kObj := GetKuadrantFromTopology(topology) + if kObj == nil { + return kuadrant.EnforcedCondition(policy, kuadrant.NewErrSystemResource("kuadrant"), false) + } policyKind := kuadrantv1.AuthPolicyGroupKind.Kind effectivePolicies, ok := state.Load(StateEffectiveAuthPolicies) @@ -182,9 +186,9 @@ func (r *AuthPolicyStatusUpdater) enforcedCondition(policy *kuadrantv1.AuthPolic var componentsToSync []string // check the status of Authorino - authorino, err := GetAuthorinoFromTopology(topology) - if err != nil { - return kuadrant.EnforcedCondition(policy, kuadrant.NewErrUnknown(policyKind, err), false) + authorino := GetAuthorinoFromTopology(topology) + if authorino == nil { + return kuadrant.EnforcedCondition(policy, kuadrant.NewErrSystemResource("authornio"), false) } if !meta.IsStatusConditionTrue(lo.Map(authorino.Status.Conditions, authorinoOperatorConditionToProperConditionFunc), string(authorinooperatorv1beta1.ConditionReady)) { componentsToSync = append(componentsToSync, kuadrantv1beta1.AuthorinoGroupKind.Kind) diff --git a/controllers/auth_workflow_helpers.go b/controllers/auth_workflow_helpers.go index 3e28d7c2d..67be530d7 100644 --- a/controllers/auth_workflow_helpers.go +++ b/controllers/auth_workflow_helpers.go @@ -34,21 +34,21 @@ var ( ErrMissingStateEffectiveAuthPolicies = fmt.Errorf("missing auth effective policies stored in the reconciliation state") ) -func GetAuthorinoFromTopology(topology *machinery.Topology) (*authorinooperatorv1beta1.Authorino, error) { +func GetAuthorinoFromTopology(topology *machinery.Topology) *authorinooperatorv1beta1.Authorino { kuadrant := GetKuadrantFromTopology(topology) if kuadrant == nil { - return nil, ErrMissingKuadrant + return nil } authorinoObj, found := lo.Find(topology.Objects().Children(kuadrant), func(child machinery.Object) bool { return child.GroupVersionKind().GroupKind() == kuadrantv1beta1.AuthorinoGroupKind }) if !found { - return nil, ErrMissingAuthorino + return nil } authorino := authorinoObj.(*controller.RuntimeObject).Object.(*authorinooperatorv1beta1.Authorino) - return authorino, nil + return authorino } func AuthObjectLabels() labels.Set { diff --git a/controllers/authconfigs_reconciler.go b/controllers/authconfigs_reconciler.go index 9e840906d..d409cb4e3 100644 --- a/controllers/authconfigs_reconciler.go +++ b/controllers/authconfigs_reconciler.go @@ -2,7 +2,6 @@ package controllers import ( "context" - "errors" "fmt" "reflect" "sync" @@ -47,13 +46,10 @@ func (r *AuthConfigsReconciler) Subscription() controller.Subscription { func (r *AuthConfigsReconciler) Reconcile(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, state *sync.Map) error { logger := controller.LoggerFromContext(ctx).WithName("AuthConfigsReconciler") - authorino, err := GetAuthorinoFromTopology(topology) - if err != nil { - if errors.Is(err, ErrMissingKuadrant) || errors.Is(err, ErrMissingAuthorino) { - logger.V(1).Info(err.Error()) - return nil - } - return err + authorino := GetAuthorinoFromTopology(topology) + if authorino == nil { + logger.V(1).Info("authorino resource not found in the topology") + return nil } authConfigsNamespace := authorino.GetNamespace() diff --git a/controllers/kuadrant_status_updater.go b/controllers/kuadrant_status_updater.go index 100c9fedf..4f96068b6 100644 --- a/controllers/kuadrant_status_updater.go +++ b/controllers/kuadrant_status_updater.go @@ -142,10 +142,10 @@ func (r *KuadrantStatusUpdater) readyCondition(topology *machinery.Topology, log } func checkLimitadorReady(topology *machinery.Topology, logger logr.Logger) *string { - limitadorObj, err := GetLimitadorFromTopology(topology) - if err != nil { - logger.V(1).Error(err, "failed getting Limitador resource from topology", "status", "error") - return ptr.To(err.Error()) + limitadorObj := GetLimitadorFromTopology(topology) + if limitadorObj == nil { + logger.V(1).Info("failed getting Limitador resource from topology", "status", "error") + return ptr.To("limitador resoure not in topology") } statusConditionReady := meta.FindStatusCondition(limitadorObj.Status.Conditions, "Ready") @@ -160,10 +160,10 @@ func checkLimitadorReady(topology *machinery.Topology, logger logr.Logger) *stri } func checkAuthorinoAvailable(topology *machinery.Topology, logger logr.Logger) *string { - authorinoObj, err := GetAuthorinoFromTopology(topology) - if err != nil { - logger.V(1).Error(err, "failed getting Authorino resource from topology", "status", "error") - return ptr.To(err.Error()) + authorinoObj := GetAuthorinoFromTopology(topology) + if authorinoObj == nil { + logger.V(1).Info("failed getting Authorino resource from topology", "status", "error") + return ptr.To("authorino resoure not in topology") } readyCondition := authorino.FindAuthorinoStatusCondition(authorinoObj.Status.Conditions, "Ready") diff --git a/controllers/limitador_limits_reconciler.go b/controllers/limitador_limits_reconciler.go index 702d896ea..406cbf572 100644 --- a/controllers/limitador_limits_reconciler.go +++ b/controllers/limitador_limits_reconciler.go @@ -2,7 +2,6 @@ package controllers import ( "context" - "errors" "fmt" "sync" @@ -43,13 +42,10 @@ func (r *LimitadorLimitsReconciler) Subscription() controller.Subscription { func (r *LimitadorLimitsReconciler) Reconcile(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, state *sync.Map) error { logger := controller.LoggerFromContext(ctx).WithName("LimitadorLimitsReconciler") - limitador, err := GetLimitadorFromTopology(topology) - if err != nil { - if errors.Is(err, ErrMissingKuadrant) || errors.Is(err, ErrMissingLimitador) { - logger.V(1).Info(err.Error()) - return nil - } - return err + limitador := GetLimitadorFromTopology(topology) + if limitador == nil { + logger.V(1).Info("not limitador resources found in topology") + return nil } desiredLimits, err := r.buildLimitadorLimits(ctx, state) diff --git a/controllers/ratelimit_policy_status_updater.go b/controllers/ratelimit_policy_status_updater.go index e0094c43a..2256199dd 100644 --- a/controllers/ratelimit_policy_status_updater.go +++ b/controllers/ratelimit_policy_status_updater.go @@ -177,9 +177,9 @@ func (r *RateLimitPolicyStatusUpdater) enforcedCondition(policy *kuadrantv1.Rate if limitadorLimitsModified, stateLimitadorLimitsModifiedPresent := state.Load(StateLimitadorLimitsModified); stateLimitadorLimitsModifiedPresent && limitadorLimitsModified.(bool) { componentsToSync = append(componentsToSync, kuadrantv1beta1.LimitadorGroupKind.Kind) } else { - limitador, err := GetLimitadorFromTopology(topology) - if err != nil { - return kuadrant.EnforcedCondition(policy, kuadrant.NewErrUnknown(policyKind, err), false) + limitador := GetLimitadorFromTopology(topology) + if limitador == nil { + return kuadrant.EnforcedCondition(policy, kuadrant.NewErrSystemResource("limitador"), false) } if !meta.IsStatusConditionTrue(limitador.Status.Conditions, limitadorv1alpha1.StatusConditionReady) { componentsToSync = append(componentsToSync, kuadrantv1beta1.LimitadorGroupKind.Kind) diff --git a/controllers/ratelimit_workflow_helpers.go b/controllers/ratelimit_workflow_helpers.go index 34a830abe..b78858cb2 100644 --- a/controllers/ratelimit_workflow_helpers.go +++ b/controllers/ratelimit_workflow_helpers.go @@ -39,21 +39,21 @@ var ( ErrMissingStateEffectiveRateLimitPolicies = fmt.Errorf("missing rate limit effective policies stored in the reconciliation state") ) -func GetLimitadorFromTopology(topology *machinery.Topology) (*limitadorv1alpha1.Limitador, error) { +func GetLimitadorFromTopology(topology *machinery.Topology) *limitadorv1alpha1.Limitador { kuadrant := GetKuadrantFromTopology(topology) if kuadrant == nil { - return nil, nil + return nil } limitadorObj, found := lo.Find(topology.Objects().Children(kuadrant), func(child machinery.Object) bool { return child.GroupVersionKind().GroupKind() == kuadrantv1beta1.LimitadorGroupKind }) if !found { - return nil, ErrMissingLimitador + return nil } limitador := limitadorObj.(*controller.RuntimeObject).Object.(*limitadorv1alpha1.Limitador) - return limitador, nil + return limitador } func LimitsNamespaceFromRoute(route *gatewayapiv1.HTTPRoute) string {