Skip to content

Commit

Permalink
fix getAppDetails correct deployments
Browse files Browse the repository at this point in the history
Ref: SRX-2CSAEK
  • Loading branch information
sven-urbanski-freiheit-com committed Nov 5, 2024
1 parent 73f2cfd commit f6e991f
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions services/cd-service/pkg/service/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,31 +190,47 @@ func (o *OverviewServiceServer) GetAppDetails(
return nil, fmt.Errorf("could not obtain deployments for app %s: %w", appName, err)
}
for envName, currentDeployment := range deployments {
deployment := &api.Deployment{
Version: uint64(*currentDeployment.Version),
QueuedVersion: 0,
UndeployVersion: false,
DeploymentMetaData: &api.Deployment_DeploymentMetaData{
CiLink: currentDeployment.Metadata.CiLink,
DeployAuthor: currentDeployment.Metadata.DeployedByName,
DeployTime: currentDeployment.Created.String(),
},
environment, err := o.DBHandler.DBSelectEnvironment(ctx, transaction, envName)
if err != nil {
return nil, fmt.Errorf("failed to obtain environment %s for app %s: %w", envName, appName, err)
}
if queuedVersion, err := o.Repository.State().GetQueuedVersion(ctx, transaction, envName, appName); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
} else {
if queuedVersion == nil {
deployment.QueuedVersion = 0
} else {
deployment.QueuedVersion = *queuedVersion
if environment == nil {
return nil, fmt.Errorf("could not obtain environment %s for app %s", envName, appName)
}
foundApp := false // only apps that are active on that environment should be returned here
for _, appInEnv := range environment.Applications {
if appInEnv == appName {
foundApp = true
break
}
}
if foundApp {
deployment := &api.Deployment{
Version: uint64(*currentDeployment.Version),
QueuedVersion: 0,
UndeployVersion: false,
DeploymentMetaData: &api.Deployment_DeploymentMetaData{
CiLink: currentDeployment.Metadata.CiLink,
DeployAuthor: currentDeployment.Metadata.DeployedByName,
DeployTime: currentDeployment.Created.String(),
},
}
if queuedVersion, err := o.Repository.State().GetQueuedVersion(ctx, transaction, envName, appName); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
} else {
if queuedVersion == nil {
deployment.QueuedVersion = 0
} else {
deployment.QueuedVersion = *queuedVersion
}
}

rel := getReleaseFromVersion(releases, uint64(*currentDeployment.Version))
if rel != nil {
deployment.UndeployVersion = rel.Metadata.UndeployVersion
rel := getReleaseFromVersion(releases, uint64(*currentDeployment.Version))
if rel != nil {
deployment.UndeployVersion = rel.Metadata.UndeployVersion
}
response.Deployments[envName] = deployment
}
response.Deployments[envName] = deployment
}
result.UndeploySummary = deriveUndeploySummary(appName, response.Deployments)
result.Warnings = CalculateWarnings(deployments, appLocks, envGroups)
Expand Down Expand Up @@ -352,7 +368,17 @@ func (o *OverviewServiceServer) StreamOverview(in *api.GetOverviewRequest,
case <-o.Shutdown:
return nil
case <-ch:
ov := o.response.Load().(*api.GetOverviewResponse)
loaded := o.response.Load()
var ov *api.GetOverviewResponse = nil
if loaded == nil {
ov, err := o.getOverviewDB(stream.Context(), o.Repository.State())
if err != nil {
return fmt.Errorf("could not load overview")
}
o.response.Store(ov)
} else {
ov = loaded.(*api.GetOverviewResponse)
}

if err := stream.Send(ov); err != nil {
// if we don't log this here, the details will be lost - so this is an exception to the rule "either return an error or log it".
Expand Down Expand Up @@ -467,6 +493,10 @@ func (o *OverviewServiceServer) update(s *repository.State) {
logger.FromContext(o.Context).Error("error getting overview:", zap.Error(err))
return
}
if r == nil {
logger.FromContext(o.Context).Error("overview is nil")
return
}
o.response.Store(r)
o.notify.Notify()
}
Expand Down

0 comments on commit f6e991f

Please sign in to comment.