Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getAppDetails correct deployments #2084

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 0 additions & 8 deletions services/cd-service/pkg/service/overview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,6 @@ func TestOverviewAndAppDetails(t *testing.T) {
DeployAuthor: "test tester",
},
},
prod: {
Version: 3,
QueuedVersion: 0,
UndeployVersion: false,
DeploymentMetaData: &api.Deployment_DeploymentMetaData{
DeployAuthor: "test tester",
},
},
},
AppLocks: map[string]*api.Locks{},
TeamLocks: map[string]*api.Locks{},
Expand Down
Loading