From cf17283ebed196f44fa1bba38afe5a5cfdc18ee2 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 24 May 2024 16:52:42 -0400 Subject: [PATCH] fix source ordering issue in manifest generation for multi-source app while using manifests and diff commands (#18395) (#18408) --- server/application/application.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/application/application.go b/server/application/application.go index 19d80303c2dfd..ed73938cc596d 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -469,15 +469,16 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan } sources := make([]appv1.ApplicationSource, 0) + appSpec := a.Spec.DeepCopy() if a.Spec.HasMultipleSources() { numOfSources := int64(len(a.Spec.GetSources())) for i, pos := range q.SourcePositions { if pos <= 0 || pos > numOfSources { return fmt.Errorf("source position is out of range") } - a.Spec.Sources[pos-1].TargetRevision = q.Revisions[i] + appSpec.Sources[pos-1].TargetRevision = q.Revisions[i] } - sources = a.Spec.GetSources() + sources = appSpec.GetSources() } else { source := a.Spec.GetSource() if q.GetRevision() != "" { @@ -487,7 +488,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan } // Store the map of all sources having ref field into a map for applications with sources field - refSources, err := argo.GetRefSources(context.Background(), a.Spec, s.db) + refSources, err := argo.GetRefSources(context.Background(), *appSpec, s.db) if err != nil { return fmt.Errorf("failed to get ref sources: %v", err) } @@ -560,7 +561,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan manifestInfo.Manifests[i] = string(data) } } - manifests.Manifests = manifestInfo.Manifests + manifests.Manifests = append(manifests.Manifests, manifestInfo.Manifests...) } return manifests, nil