diff --git a/api/http/handler/gitops/workflows/list.go b/api/http/handler/gitops/workflows/list.go index d484ea280..dc744cbf9 100644 --- a/api/http/handler/gitops/workflows/list.go +++ b/api/http/handler/gitops/workflows/list.go @@ -142,6 +142,8 @@ func (h *Handler) getWorkflows(ctx context.Context, key string, sc *security.Res func (h *Handler) fetchWorkflows(ctx context.Context, sc *security.RestrictedRequestContext, endpointIDSet set.Set[portainer.EndpointID]) ([]svc.Workflow, error) { var entries []portainer.Stack + var endpointMap map[portainer.EndpointID]portainer.Endpoint + err := h.dataStore.ViewTx(func(tx dataservices.DataStoreTx) error { stacks, err := tx.Stack().ReadAll(func(s portainer.Stack) bool { return s.GitConfig != nil && (len(endpointIDSet) == 0 || endpointIDSet.Contains(s.EndpointID)) @@ -150,7 +152,7 @@ func (h *Handler) fetchWorkflows(ctx context.Context, sc *security.RestrictedReq return err } - endpointMap, err := buildEndpointMap(tx, stacks) + endpointMap, err = buildEndpointMap(tx, stacks) if err != nil { return err } @@ -169,16 +171,15 @@ func (h *Handler) fetchWorkflows(ctx context.Context, sc *security.RestrictedReq entries = append(entries, s) } - entries, err = filterK8SStacks(entries, endpointMap, h.k8sFactory, sc.UserID) - if err != nil { - return err - } - return nil }) if err != nil { return nil, err } + entries, err = filterK8SStacks(entries, endpointMap, h.k8sFactory, sc.UserID) + if err != nil { + return nil, err + } items := make([]svc.Workflow, 0, len(entries)) for _, s := range entries {