Skip to content

Commit

Permalink
fix: fix-lock-prevented deployment & overview error (#1798)
Browse files Browse the repository at this point in the history
When creating an undeploy application version and an lock existed, a
lock prevented deployment event was generated. Undeploy versions have no
commit id and events require one. Fix was to not generate this event (by
throwing an error)if we can't find a commit ID (equal to what we did
with the manifest repo)

Also, the overview wasn't getting correctly updated.

REF: SRX-0E8EKB
  • Loading branch information
miguel-crespo-fdc authored Jul 25, 2024
1 parent e9558a5 commit 8a4e1c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 43 additions & 1 deletion pkg/db/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,22 @@ func (h *DBHandler) UpdateOverviewDeployment(ctx context.Context, transaction *s
}
appInEnv.DeploymentMetaData.DeployAuthor = deployment.Metadata.DeployedByEmail
appInEnv.DeploymentMetaData.DeployTime = fmt.Sprintf("%d", createdTime.Unix())

app := getApplicationByName(latestOverview.Applications, deployment.App)
app.Warnings = CalculateWarnings(ctx, app.Name, latestOverview.EnvironmentGroups)

if deployment.Version != nil { //Check if not trying to deploy an undeploy version
//Get the undeploy information from the release
release, err := h.DBSelectReleaseByVersion(ctx, transaction, appInEnv.Name, appInEnv.Version)
if err != nil {
return fmt.Errorf("error getting release %d for app %s", appInEnv.Version, appInEnv.Name)
}
if release == nil {
return fmt.Errorf("could not find release %d for app %s", appInEnv.Version, appInEnv.Name)
}
appInEnv.UndeployVersion = release.Metadata.UndeployVersion
}
app.Warnings = CalculateWarnings(ctx, app.Name, latestOverview.EnvironmentGroups)
app.UndeploySummary = deriveUndeploySummary(app.Name, latestOverview.EnvironmentGroups)
err = h.WriteOverviewCache(ctx, transaction, latestOverview)
if err != nil {
return err
Expand Down Expand Up @@ -160,6 +173,35 @@ func (h *DBHandler) UpdateOverviewDeploymentAttempt(ctx context.Context, transac
return nil
}

func deriveUndeploySummary(appName string, groups []*api.EnvironmentGroup) api.UndeploySummary {
var allNormal = true
var allUndeploy = true
for _, group := range groups {
for _, environment := range group.Environments {
var app, exists = environment.Applications[appName]
if !exists {
continue
}
if app.Version == 0 {
// if the app exists but nothing is deployed, we ignore this
continue
}
if app.UndeployVersion {
allNormal = false
} else {
allUndeploy = false
}
}
}
if allUndeploy {
return api.UndeploySummary_UNDEPLOY
}
if allNormal {
return api.UndeploySummary_NORMAL
}
return api.UndeploySummary_MIXED
}

func (h *DBHandler) UpdateOverviewApplicationLock(ctx context.Context, transaction *sql.Tx, applicationLock ApplicationLock) error {
latestOverview, err := h.ReadLatestOverviewCache(ctx, transaction)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions services/cd-service/pkg/repository/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2881,6 +2881,9 @@ func getCommitID(ctx context.Context, transaction *sql.Tx, state *State, fs bill
if tmp == nil {
return "", fmt.Errorf("release %v not found for app %s", release, app)
}
if tmp.Metadata.SourceCommitId == "" {
return "", fmt.Errorf("Found release %v for app %s, but commit id was empty", release, app)
}
return tmp.Metadata.SourceCommitId, nil
} else {
return getCommitIDFromReleaseDir(ctx, fs, releaseDir)
Expand Down

0 comments on commit 8a4e1c0

Please sign in to comment.