Skip to content

Commit 28fcc76

Browse files
committed
Fix domain filtering for multi-cluster HTTPRoutes
Store per-cluster domain filters in HTTPRoute annotations and use them when generating Homer config items. This ensures that HTTPRoutes with multiple hostnames only show the hostnames matching the cluster's domain filter. Changes: - Store domain filters as annotation on HTTPRoutes in cluster_manager - Read domain-filters annotation in Homer config generator - Remove duplicate domain filtering in dashboard controller - Pass nil domain filters since filtering is done per-HTTPRoute
1 parent 7e9873f commit 28fcc76

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

internal/controller/cluster_manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/sha256"
2222
"encoding/hex"
2323
"fmt"
24+
"strings"
2425
"sync"
2526
"time"
2627

@@ -523,6 +524,11 @@ func (m *ClusterManager) discoverClusterHTTPRoutes(ctx context.Context, cluster
523524
}
524525
clusterHTTPRoutes.Items[i].Annotations["homer.rajsingh.info/cluster"] = cluster.Name
525526

527+
// Store domain filters as annotation so Homer config generator knows which hostnames to show
528+
if len(domainFilters) > 0 {
529+
clusterHTTPRoutes.Items[i].Annotations["homer.rajsingh.info/domain-filters"] = strings.Join(domainFilters, ",")
530+
}
531+
526532
filtered = append(filtered, clusterHTTPRoutes.Items[i])
527533
}
528534
}

internal/controller/dashboard_controller.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,13 @@ func (r *DashboardReconciler) createConfigMap(ctx context.Context, homerConfig *
872872
// Continue with partial results
873873
}
874874

875-
// Aggregate all discovered HTTPRoutes
875+
// Aggregate all discovered HTTPRoutes (already filtered by ClusterManager)
876876
for clusterName, httproutes := range clusterHTTPRoutes {
877877
log := log.FromContext(ctx)
878878
log.V(1).Info("Discovered HTTPRoutes from cluster", "cluster", clusterName, "count", len(httproutes))
879879

880-
// Apply domain filters (already filtered by ClusterManager but apply domain filters)
881-
for _, httproute := range httproutes {
882-
if homer.MatchesDomainFilters(r.getHTTPRouteHosts(&httproute), dashboard.Spec.DomainFilters) {
883-
filteredHTTPRoutes = append(filteredHTTPRoutes, httproute)
884-
}
885-
}
880+
// HTTPRoutes are already filtered by ClusterManager with per-cluster domain filters
881+
filteredHTTPRoutes = append(filteredHTTPRoutes, httproutes...)
886882
}
887883
} else {
888884
// Fall back to single-cluster discovery
@@ -902,7 +898,9 @@ func (r *DashboardReconciler) createConfigMap(ctx context.Context, homerConfig *
902898
}
903899
}
904900

905-
return homer.CreateConfigMapWithHTTPRoutes(homerConfig, dashboard.Name, dashboard.Namespace, filteredIngressList, filteredHTTPRoutes, dashboard, dashboard.Spec.DomainFilters)
901+
// Don't pass domain filters since HTTPRoutes are already filtered by ClusterManager
902+
// and we want to show all hostnames from each HTTPRoute
903+
return homer.CreateConfigMapWithHTTPRoutes(homerConfig, dashboard.Name, dashboard.Namespace, filteredIngressList, filteredHTTPRoutes, dashboard, nil)
906904
}
907905

908906
return homer.CreateConfigMap(homerConfig, dashboard.Name, dashboard.Namespace, filteredIngressList, dashboard)

pkg/homer/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,11 +1250,21 @@ func updateHomerConfigWithHTTPRoutes(
12501250
// This allows for cleanup when all hostnames are removed
12511251
return
12521252
} else {
1253+
// Check if HTTPRoute has per-cluster domain filters annotation
1254+
effectiveDomainFilters := domainFilters
1255+
if filterAnnotation, ok := httproute.ObjectMeta.Annotations["homer.rajsingh.info/domain-filters"]; ok && filterAnnotation != "" {
1256+
// Use per-cluster domain filters from annotation
1257+
effectiveDomainFilters = strings.Split(filterAnnotation, ",")
1258+
for i := range effectiveDomainFilters {
1259+
effectiveDomainFilters[i] = strings.TrimSpace(effectiveDomainFilters[i])
1260+
}
1261+
}
1262+
12531263
// Create separate item for each hostname that matches domain filters
12541264
var filteredHostnames []gatewayv1.Hostname
12551265
for _, hostname := range httproute.Spec.Hostnames {
12561266
hostStr := string(hostname)
1257-
if utils.MatchesHostDomainFilters(hostStr, domainFilters) {
1267+
if utils.MatchesHostDomainFilters(hostStr, effectiveDomainFilters) {
12581268
filteredHostnames = append(filteredHostnames, hostname)
12591269
}
12601270
}

0 commit comments

Comments
 (0)