Skip to content

Commit

Permalink
UPDATE: PR comments
Browse files Browse the repository at this point in the history
Add changes based on PR comments

Signed-off-by: Jim Fitzpatrick <[email protected]>
  • Loading branch information
Boomatang committed Nov 13, 2024
1 parent 1aff0b2 commit f6e4f62
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
10 changes: 7 additions & 3 deletions controllers/auth_policy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions controllers/auth_workflow_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions controllers/authconfigs_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"context"
"errors"
"fmt"
"reflect"
"sync"
Expand Down Expand Up @@ -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()

Expand Down
12 changes: 4 additions & 8 deletions controllers/kuadrant_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"context"
"errors"
"fmt"
"slices"
"sync"
Expand Down Expand Up @@ -127,10 +126,7 @@ func (r *KuadrantStatusUpdater) readyCondition(topology *machinery.Topology, log
return cond
}

limitadorObj, err := GetLimitadorFromTopology(topology)
if err != nil && !errors.Is(err, ErrMissingLimitador) {
logger.V(1).Error(err, "failed getting Limitador resource from topology", "status", "error")
}
limitadorObj := GetLimitadorFromTopology(topology)

if limitadorObj != nil {
reason := checkLimitadorReady(limitadorObj)
Expand All @@ -142,9 +138,9 @@ func (r *KuadrantStatusUpdater) readyCondition(topology *machinery.Topology, log
}
}

authorinoObj, err := GetAuthorinoFromTopology(topology)
if err != nil && !errors.Is(err, ErrMissingAuthorino) {
logger.V(1).Error(err, "failed getting Authorino resource from topology", "status", "error")
authorinoObj := GetAuthorinoFromTopology(topology)
if authorinoObj == nil {
logger.V(1).Info("Authorino resource not in topology", "status", "error")
}

if authorinoObj != nil {
Expand Down
12 changes: 4 additions & 8 deletions controllers/limitador_limits_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"context"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions controllers/ratelimit_policy_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions controllers/ratelimit_workflow_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f6e4f62

Please sign in to comment.