Skip to content

Commit

Permalink
refactor based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Boomatang committed Apr 18, 2024
1 parent 17378e0 commit 7efe3c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
13 changes: 7 additions & 6 deletions controllers/authpolicy_authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"reflect"
"strings"

"k8s.io/utils/ptr"

"github.com/go-logr/logr"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -188,7 +190,8 @@ func routeGatewayHasAuthOverrides(ctx context.Context, route *gatewayapiv1.HTTPR
for idx := range route.Spec.ParentRefs {
parentRef := route.Spec.ParentRefs[idx]
gw := &gatewayapiv1.Gateway{}
err := c.Get(ctx, client.ObjectKey{Name: string(parentRef.Name), Namespace: string(*parentRef.Namespace)}, gw)
namespace := ptr.Deref(parentRef.Namespace, gatewayapiv1.Namespace(route.GetNamespace()))
err := c.Get(ctx, client.ObjectKey{Name: string(parentRef.Name), Namespace: string(namespace)}, gw)
if err != nil {
return false, err
}
Expand All @@ -197,15 +200,13 @@ func routeGatewayHasAuthOverrides(ctx context.Context, route *gatewayapiv1.HTTPR
if !ok {
continue
}
anno := strings.Split(annotation, "/")
ap := &api.AuthPolicy{}
err = c.Get(ctx, client.ObjectKey{Name: anno[1], Namespace: anno[0]}, ap)
otherAP := &api.AuthPolicy{}
err = c.Get(ctx, utils.NamespacedNameToObjectKey(annotation, gw.Namespace), otherAP)
if err != nil {
return false, err
}

override := ap.IsAtomicOverride()
if override {
if otherAP.IsAtomicOverride() {
return true, nil
}
}
Expand Down
13 changes: 2 additions & 11 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,9 @@ func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.A
// this is due to not knowing if the Gateway AuthPolicy was updated to include or remove the overrides section.
switch obj := targetNetworkObject.(type) {
case *gatewayapiv1.Gateway:
gw := kuadrant.GatewayWrapper{Gateway: obj}
annotation, ok := gw.GetAnnotations()[ap.BackReferenceAnnotationName()]
if !ok {
break
}
policyKeys := &[]client.ObjectKey{}
gw := kuadrant.GatewayWrapper{Gateway: obj, Referrer: ap}
apKey := client.ObjectKeyFromObject(ap)
err = json.Unmarshal([]byte(annotation), policyKeys)
if err != nil {
return err
}
for _, policyKey := range *policyKeys {
for _, policyKey := range gw.PolicyRefs() {
if policyKey == apKey {
continue
}
Expand Down

0 comments on commit 7efe3c9

Please sign in to comment.