@@ -7,11 +7,13 @@ import (
77
88 "github.com/go-logr/logr"
99 "github.com/pkg/errors"
10+ "golang.org/x/exp/slices"
1011 corev1 "k8s.io/api/core/v1"
1112 discoveryv1 "k8s.io/api/discovery/v1"
1213 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314 "k8s.io/apimachinery/pkg/runtime"
1415 "k8s.io/apimachinery/pkg/types"
16+ "k8s.io/utils/ptr"
1517 ctrl "sigs.k8s.io/controller-runtime"
1618 "sigs.k8s.io/controller-runtime/pkg/builder"
1719 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -98,6 +100,9 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
98100 hr := new (gatewayv1.HTTPRoute )
99101 if err := r .Get (ctx , req .NamespacedName , hr ); err != nil {
100102 if client .IgnoreNotFound (err ) == nil {
103+ if err := r .updateHTTPRoutePolicyStatusOnDeleting (req .NamespacedName ); err != nil {
104+ return ctrl.Result {}, err
105+ }
101106 hr .Namespace = req .Namespace
102107 hr .Name = req .Name
103108
@@ -514,21 +519,14 @@ func httpRoutePolicyPredicateFuncs(channel chan event.GenericEvent) predicate.Pr
514519 if ! ok0 || ! ok1 {
515520 return false
516521 }
517- var discardsRefs = make (map [string ]v1alpha2.LocalPolicyTargetReferenceWithSectionName )
518- for _ , ref := range oldPolicy .Spec .TargetRefs {
519- key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
520- discardsRefs [key ] = ref
521- }
522- for _ , ref := range newPolicy .Spec .TargetRefs {
523- key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
524- delete (discardsRefs , key )
525- }
522+ discardsRefs := slices .DeleteFunc (oldPolicy .Spec .TargetRefs , func (oldRef v1alpha2.LocalPolicyTargetReferenceWithSectionName ) bool {
523+ return slices .ContainsFunc (newPolicy .Spec .TargetRefs , func (newRef v1alpha2.LocalPolicyTargetReferenceWithSectionName ) bool {
524+ return oldRef .LocalPolicyTargetReference == newRef .LocalPolicyTargetReference && ptr .Equal (oldRef .SectionName , newRef .SectionName )
525+ })
526+ })
526527 if len (discardsRefs ) > 0 {
527528 dump := oldPolicy .DeepCopy ()
528- dump .Spec .TargetRefs = make ([]v1alpha2.LocalPolicyTargetReferenceWithSectionName , 0 , len (discardsRefs ))
529- for _ , ref := range discardsRefs {
530- dump .Spec .TargetRefs = append (dump .Spec .TargetRefs , ref )
531- }
529+ dump .Spec .TargetRefs = discardsRefs
532530 channel <- event.GenericEvent {Object : dump }
533531 }
534532 return true
0 commit comments