diff --git a/pkg/db/overview.go b/pkg/db/overview.go index 59a62052e..f75848579 100644 --- a/pkg/db/overview.go +++ b/pkg/db/overview.go @@ -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 @@ -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 { diff --git a/services/cd-service/pkg/repository/transformer.go b/services/cd-service/pkg/repository/transformer.go index aedf15f38..061e71afc 100644 --- a/services/cd-service/pkg/repository/transformer.go +++ b/services/cd-service/pkg/repository/transformer.go @@ -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)