Skip to content

Commit

Permalink
fix source ordering issue in manifest generation for multi-source app…
Browse files Browse the repository at this point in the history
… while using manifests and diff commands (#18395) (#18408)
  • Loading branch information
gcp-cherry-pick-bot[bot] authored May 24, 2024
1 parent 25f7504 commit cf17283
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() != "" {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf17283

Please sign in to comment.