Skip to content

Commit

Permalink
fix: improve upstreamlatest release trains
Browse files Browse the repository at this point in the history
previously the release train to "latest" would consider all apps.
Now it only considers apps that exist (have a release) in the target env.

Ref: SRX-LEIHOZ
  • Loading branch information
sven-urbanski-freiheit-com committed Oct 10, 2024
1 parent 411e19a commit 9ecb8bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions services/cd-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,9 @@ func (s *State) GetEnvironmentApplicationsFromDB(ctx context.Context, transactio
if err != nil {
return nil, err
}
if envInfo == nil {
return nil, fmt.Errorf("environment %s not found", environment)
}
if envInfo.Applications == nil {
return make([]string, 0), nil
}
Expand Down
8 changes: 5 additions & 3 deletions services/cd-service/pkg/repository/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3382,7 +3382,7 @@ func getOverrideVersions(ctx context.Context, transaction *sql.Tx, commitHash, u
return resp, nil
}

func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sql.Tx, upstreamLatest bool, state *State, upstreamEnvName, source, commitHash string) (apps []string, appVersions []Overview, err error) {
func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sql.Tx, upstreamLatest bool, state *State, upstreamEnvName, source, commitHash string, targetEnv string) (apps []string, appVersions []Overview, err error) {
if commitHash != "" {
appVersions, err := getOverrideVersions(ctx, transaction, c.CommitHash, upstreamEnvName, c.Repo)
if err != nil {
Expand All @@ -3403,7 +3403,9 @@ func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sq
return apps, appVersions, nil
}
if upstreamLatest {
apps, err = state.GetApplications(ctx, transaction)
// For "upstreamlatest" we cannot get the source environment, because it's not a real environment
// but since we only care about the names of the apps, we can just get the apps for the target env.
apps, err = state.GetEnvironmentApplications(ctx, transaction, targetEnv)
if err != nil {
return nil, nil, grpc.PublicError(ctx, fmt.Errorf("could not get all applications for %q: %w", source, err))
}
Expand Down Expand Up @@ -3704,7 +3706,7 @@ func (c *envReleaseTrain) prognosis(
source = "latest"
}

apps, overrideVersions, err := c.Parent.getUpstreamLatestApp(ctx, transaction, upstreamLatest, state, upstreamEnvName, source, c.Parent.CommitHash)
apps, overrideVersions, err := c.Parent.getUpstreamLatestApp(ctx, transaction, upstreamLatest, state, upstreamEnvName, source, c.Parent.CommitHash, c.Env)
if err != nil {
return ReleaseTrainEnvironmentPrognosis{
SkipCause: nil,
Expand Down

0 comments on commit 9ecb8bd

Please sign in to comment.