From ac37d37f945fc182a2b150f676dd4dcf25b06f75 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Sun, 21 Jun 2026 05:13:24 +0000 Subject: [PATCH] fix(deploymentstore): return oldest uncompleted deployment as head The head deployment selection in ListAppHeadDeployments was inverted. The previous loop order (pendings -> planneds -> runnings) caused newer statuses to overwrite older ones, so the newest uncompleted deployment was returned instead of the oldest. Fix: iterate runnings first (oldest), then planneds and pendings only if no entry exists for that application ID. This matches the Lister interface docstring: 'Head deployment is same with the oldest uncompleted one.' Fixes #6780 Signed-off-by: Arunesh Dwivedi --- pkg/app/piped/apistore/deploymentstore/store.go | 12 ++++++++---- pkg/app/pipedv1/apistore/deploymentstore/store.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/app/piped/apistore/deploymentstore/store.go b/pkg/app/piped/apistore/deploymentstore/store.go index 1f8f508a5d..9bb619cd43 100644 --- a/pkg/app/piped/apistore/deploymentstore/store.go +++ b/pkg/app/piped/apistore/deploymentstore/store.go @@ -123,14 +123,18 @@ func (s *store) sync(ctx context.Context) error { } headDeployments := make(map[string]*model.Deployment) - for _, d := range pendings { + for _, d := range runnings { headDeployments[d.ApplicationId] = d } for _, d := range planneds { - headDeployments[d.ApplicationId] = d + if _, exists := headDeployments[d.ApplicationId]; !exists { + headDeployments[d.ApplicationId] = d + } } - for _, d := range runnings { - headDeployments[d.ApplicationId] = d + for _, d := range pendings { + if _, exists := headDeployments[d.ApplicationId]; !exists { + headDeployments[d.ApplicationId] = d + } } s.plannedDeployments.Store(planneds) diff --git a/pkg/app/pipedv1/apistore/deploymentstore/store.go b/pkg/app/pipedv1/apistore/deploymentstore/store.go index 1f8f508a5d..9bb619cd43 100644 --- a/pkg/app/pipedv1/apistore/deploymentstore/store.go +++ b/pkg/app/pipedv1/apistore/deploymentstore/store.go @@ -123,14 +123,18 @@ func (s *store) sync(ctx context.Context) error { } headDeployments := make(map[string]*model.Deployment) - for _, d := range pendings { + for _, d := range runnings { headDeployments[d.ApplicationId] = d } for _, d := range planneds { - headDeployments[d.ApplicationId] = d + if _, exists := headDeployments[d.ApplicationId]; !exists { + headDeployments[d.ApplicationId] = d + } } - for _, d := range runnings { - headDeployments[d.ApplicationId] = d + for _, d := range pendings { + if _, exists := headDeployments[d.ApplicationId]; !exists { + headDeployments[d.ApplicationId] = d + } } s.plannedDeployments.Store(planneds)