@@ -97,32 +97,6 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
9797 Complete (r )
9898}
9999
100- func (r * HTTPRouteReconciler ) httpRoutePolicyPredicateOnUpdate (e event.UpdateEvent ) bool {
101- oldPolicy , ok0 := e .ObjectOld .(* v1alpha1.HTTPRoutePolicy )
102- newPolicy , ok1 := e .ObjectNew .(* v1alpha1.HTTPRoutePolicy )
103- if ! ok0 || ! ok1 {
104- return false
105- }
106- var discardsRefs = make (map [string ]v1alpha2.LocalPolicyTargetReferenceWithSectionName )
107- for _ , ref := range oldPolicy .Spec .TargetRefs {
108- key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
109- discardsRefs [key ] = ref
110- }
111- for _ , ref := range newPolicy .Spec .TargetRefs {
112- key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
113- delete (discardsRefs , key )
114- }
115- if len (discardsRefs ) > 0 {
116- dump := oldPolicy .DeepCopy ()
117- dump .Spec .TargetRefs = make ([]v1alpha2.LocalPolicyTargetReferenceWithSectionName , 0 , len (discardsRefs ))
118- for _ , ref := range discardsRefs {
119- dump .Spec .TargetRefs = append (dump .Spec .TargetRefs , ref )
120- }
121- r .genericEvent <- event.GenericEvent {Object : dump }
122- }
123- return true
124- }
125-
126100func (r * HTTPRouteReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
127101 hr := new (gatewayv1.HTTPRoute )
128102 if err := r .Get (ctx , req .NamespacedName , hr ); err != nil {
@@ -221,6 +195,7 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
221195 if err := r .Status ().Update (ctx , hr ); err != nil {
222196 return ctrl.Result {}, err
223197 }
198+ UpdateStatus (r .Client , r .Log , tctx )
224199 return ctrl.Result {}, nil
225200}
226201
@@ -311,10 +286,10 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
311286 return nil
312287 }
313288
314- var keys = make (map [ancestorRefKey ]struct {})
289+ var keys = make (map [targetRefKey ]struct {})
315290 for _ , ref := range httpRoutePolicy .Spec .TargetRefs {
316291 if ref .Kind == "HTTPRoute" {
317- key := ancestorRefKey {
292+ key := targetRefKey {
318293 Group : gatewayv1 .GroupName ,
319294 Namespace : gatewayv1 .Namespace (obj .GetNamespace ()),
320295 Name : ref .Name ,
@@ -329,8 +304,6 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
329304 var httpRoute gatewayv1.HTTPRoute
330305 if err := r .Get (ctx , client.ObjectKey {Namespace : string (key .Namespace ), Name : string (key .Name )}, & httpRoute ); err != nil {
331306 r .Log .Error (err , "failed to get HTTPRoute by HTTPRoutePolicy targetRef" , "namespace" , key .Namespace , "name" , key .Name )
332- r .modifyHTTPRoutePolicyStatus (key , httpRoutePolicy , false , string (v1alpha2 .PolicyReasonTargetNotFound ), "not found target HTTPRoute" )
333- r .Log .Info ("status after modified" , "key" , key , "status" , httpRoutePolicy .Status .Ancestors )
334307 continue
335308 }
336309 if key .SectionName != "" {
@@ -343,7 +316,6 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
343316 }
344317 if ! matchRuleName {
345318 r .Log .Error (errors .Errorf ("failed to get HTTPRoute rule by HTTPRoutePolicy targetRef" ), "namespace" , key .Namespace , "name" , key .Name , "sectionName" , key .SectionName )
346- r .modifyHTTPRoutePolicyStatus (key , httpRoutePolicy , false , string (v1alpha2 .PolicyReasonTargetNotFound ), "not found target HTTPRoute rule" )
347319 continue
348320 }
349321 }
@@ -355,15 +327,6 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
355327 })
356328 }
357329
358- r .Log .Info ("status before clear" , "status" , httpRoutePolicy .Status .Ancestors )
359- r .clearHTTPRoutePolicyRedundantAncestor (httpRoutePolicy )
360- r .Log .Info ("status after clear" , "status" , httpRoutePolicy .Status .Ancestors )
361- if httpRoutePolicy .GetDeletionTimestamp ().IsZero () {
362- if err := r .Status ().Update (ctx , httpRoutePolicy ); err != nil {
363- r .Log .Error (err , "failed to update HTTPRoutePolicy status" , "namespace" , obj .GetNamespace (), "name" , obj .GetName ())
364- }
365- }
366-
367330 return requests
368331}
369332
@@ -502,3 +465,29 @@ func (r *HTTPRouteReconciler) processHTTPRoute(tctx *provider.TranslateContext,
502465
503466 return terror
504467}
468+
469+ func (r * HTTPRouteReconciler ) httpRoutePolicyPredicateOnUpdate (e event.UpdateEvent ) bool {
470+ oldPolicy , ok0 := e .ObjectOld .(* v1alpha1.HTTPRoutePolicy )
471+ newPolicy , ok1 := e .ObjectNew .(* v1alpha1.HTTPRoutePolicy )
472+ if ! ok0 || ! ok1 {
473+ return false
474+ }
475+ var discardsRefs = make (map [string ]v1alpha2.LocalPolicyTargetReferenceWithSectionName )
476+ for _ , ref := range oldPolicy .Spec .TargetRefs {
477+ key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
478+ discardsRefs [key ] = ref
479+ }
480+ for _ , ref := range newPolicy .Spec .TargetRefs {
481+ key := indexer .GenHTTPRoutePolicyIndexKey (string (ref .Group ), string (ref .Kind ), e .ObjectOld .GetNamespace (), string (ref .Name ), "" )
482+ delete (discardsRefs , key )
483+ }
484+ if len (discardsRefs ) > 0 {
485+ dump := oldPolicy .DeepCopy ()
486+ dump .Spec .TargetRefs = make ([]v1alpha2.LocalPolicyTargetReferenceWithSectionName , 0 , len (discardsRefs ))
487+ for _ , ref := range discardsRefs {
488+ dump .Spec .TargetRefs = append (dump .Spec .TargetRefs , ref )
489+ }
490+ r .genericEvent <- event.GenericEvent {Object : dump }
491+ }
492+ return true
493+ }
0 commit comments