Skip to content

Commit e20bac6

Browse files
committed
resolve comments
1 parent 216bf0e commit e20bac6

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

internal/controller/httproute_controller.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,39 +287,38 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
287287
return nil
288288
}
289289

290-
var keys = make(map[targetRefKey]struct{})
290+
var keys = make(map[types.NamespacedName]struct{})
291291
for _, ref := range httpRoutePolicy.Spec.TargetRefs {
292-
if ref.Kind == "HTTPRoute" {
293-
key := targetRefKey{
294-
Group: gatewayv1.GroupName,
295-
Namespace: gatewayv1.Namespace(obj.GetNamespace()),
296-
Name: ref.Name,
297-
}
298-
if ref.SectionName != nil {
299-
key.SectionName = *ref.SectionName
300-
}
301-
keys[key] = struct{}{}
292+
if ref.Kind != "HTTPRoute" {
293+
continue
302294
}
303-
}
304-
for key := range keys {
295+
key := types.NamespacedName{
296+
Namespace: obj.GetNamespace(),
297+
Name: string(ref.Name),
298+
}
299+
if _, ok := keys[key]; ok {
300+
continue
301+
}
302+
305303
var httpRoute gatewayv1.HTTPRoute
306304
if err := r.Get(ctx, client.ObjectKey{Namespace: string(key.Namespace), Name: string(key.Name)}, &httpRoute); err != nil {
307305
r.Log.Error(err, "failed to get HTTPRoute by HTTPRoutePolicy targetRef", "namespace", key.Namespace, "name", key.Name)
308306
continue
309307
}
310-
if key.SectionName != "" {
308+
if ref.SectionName != nil {
311309
var matchRuleName bool
312310
for _, rule := range httpRoute.Spec.Rules {
313-
if rule.Name != nil && *rule.Name == key.SectionName {
311+
if rule.Name != nil && *rule.Name == *ref.SectionName {
314312
matchRuleName = true
315313
break
316314
}
317315
}
318316
if !matchRuleName {
319-
r.Log.Error(errors.Errorf("failed to get HTTPRoute rule by HTTPRoutePolicy targetRef"), "namespace", key.Namespace, "name", key.Name, "sectionName", key.SectionName)
317+
r.Log.Error(errors.Errorf("failed to get HTTPRoute rule by HTTPRoutePolicy targetRef"), "namespace", key.Namespace, "name", key.Name, "sectionName", *ref.SectionName)
320318
continue
321319
}
322320
}
321+
keys[key] = struct{}{}
323322
requests = append(requests, reconcile.Request{
324323
NamespacedName: types.NamespacedName{
325324
Namespace: string(key.Namespace),

0 commit comments

Comments
 (0)