From 3237e1990c32123dc943fb4ff34b2d53c5e5964f Mon Sep 17 00:00:00 2001 From: cmeng Date: Thu, 24 Aug 2023 09:18:59 +1200 Subject: [PATCH] fix(waiting-room): search endpoints by dynamic edge group name EE-5965 (#10090) --- api/http/handler/endpoints/filter.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/http/handler/endpoints/filter.go b/api/http/handler/endpoints/filter.go index 3d071afc1..b001d7398 100644 --- a/api/http/handler/endpoints/filter.go +++ b/api/http/handler/endpoints/filter.go @@ -12,6 +12,7 @@ import ( portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/dataservices" "github.com/portainer/portainer/api/http/handler/edgegroups" + "github.com/portainer/portainer/api/internal/edge" "github.com/portainer/portainer/api/internal/endpointutils" "github.com/portainer/portainer/api/internal/slices" "github.com/portainer/portainer/api/internal/unique" @@ -311,11 +312,15 @@ func filterEndpointsBySearchCriteria( if endpointGroupMatchSearchCriteria(&endpoint, endpointGroups, tagsMap, searchCriteria) { endpoints[n] = endpoint n++ + + continue } - if edgeGroupMatchSearchCriteria(&endpoint, edgeGroups, searchCriteria) { + if edgeGroupMatchSearchCriteria(&endpoint, edgeGroups, searchCriteria, endpoints, endpointGroups) { endpoints[n] = endpoint n++ + + continue } } @@ -395,13 +400,18 @@ func endpointGroupMatchSearchCriteria(endpoint *portainer.Endpoint, endpointGrou return false } +// search endpoint's related edgegroups func edgeGroupMatchSearchCriteria( endpoint *portainer.Endpoint, edgeGroups []portainer.EdgeGroup, searchCriteria string, + endpoints []portainer.Endpoint, + endpointGroups []portainer.EndpointGroup, ) bool { for _, edgeGroup := range edgeGroups { - for _, endpointID := range edgeGroup.Endpoints { + relatedEndpointIDs := edge.EdgeGroupRelatedEndpoints(&edgeGroup, endpoints, endpointGroups) + + for _, endpointID := range relatedEndpointIDs { if endpointID == endpoint.ID { if strings.Contains(strings.ToLower(edgeGroup.Name), searchCriteria) { return true