Skip to content

Commit 3872082

Browse files
authored
fix: deployment status is stuck is progressing for parallel deployments in devtron application (#6591)
* fix: deployment status is stuck is progressing for parallel deployments in devtron application * fix: reverted old implementation for GetSyncStartTime/ GetSyncFinishTime func * fix: added comment for fixme
1 parent bcb1103 commit 3872082

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

pkg/app/AppService.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
555555
if err != nil {
556556
impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "cdWfrId", runnerHistoryId)
557557
}
558-
syncStartTime, found := helper.GetSyncStartTime(app)
559-
if !found {
560-
impl.logger.Warnw("sync operation not started yet", "app", app)
561-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet")
562-
}
558+
syncStartTime := helper.GetSyncStartTime(app, statusTime)
563559
// creating cd pipeline status timeline
564560
timeline := &pipelineConfig.PipelineStatusTimeline{
565561
CdWorkflowRunnerId: runnerHistoryId,
@@ -596,11 +592,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
596592
timeline.Id = 0
597593
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
598594
timeline.StatusDetail = app.Status.OperationState.Message
599-
syncFinishTime, found := helper.GetSyncFinishTime(app)
600-
if !found {
601-
impl.logger.Warnw("sync operation not found for the deployment", "app", app)
602-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment")
603-
}
595+
syncFinishTime := helper.GetSyncFinishTime(app, statusTime)
604596
timeline.StatusTime = syncFinishTime
605597
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
606598
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
@@ -679,11 +671,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
679671
if err != nil {
680672
impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "installedAppVersionHistoryId", runnerHistoryId)
681673
}
682-
syncStartTime, found := helper.GetSyncStartTime(app)
683-
if !found {
684-
impl.logger.Warnw("sync operation not started yet", "app", app)
685-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet")
686-
}
674+
syncStartTime := helper.GetSyncStartTime(app, statusTime)
687675
// creating installedAppVersionHistory status timeline
688676
timeline := &pipelineConfig.PipelineStatusTimeline{
689677
InstalledAppVersionHistoryId: runnerHistoryId,
@@ -720,11 +708,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
720708
timeline.Id = 0
721709
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
722710
timeline.StatusDetail = app.Status.OperationState.Message
723-
syncFinishTime, found := helper.GetSyncFinishTime(app)
724-
if !found {
725-
impl.logger.Warnw("sync operation not found for the deployment", "app", app)
726-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment")
727-
}
711+
syncFinishTime := helper.GetSyncFinishTime(app, statusTime)
728712
timeline.StatusTime = syncFinishTime
729713
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
730714
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
@@ -744,6 +728,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
744728
haveNewTimeline = true
745729
timeline.Status = timelineStatus.TIMELINE_STATUS_APP_HEALTHY
746730
timeline.StatusDetail = "App status is Healthy."
731+
timeline.StatusTime = statusTime
747732
}
748733
if haveNewTimeline {
749734
// not checking if this status is already present or not because already checked for terminal status existence earlier

pkg/argoApplication/helper/deploymentStatusHelper.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,40 @@ package helper
22

33
import (
44
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
"time"
67
)
78

89
// GetSyncStartTime assumes that it is always called for calculating start time of latest git hash
9-
func GetSyncStartTime(app *v1alpha1.Application) (time.Time, bool) {
10+
func GetSyncStartTime(app *v1alpha1.Application, defaultStartTime time.Time) time.Time {
11+
startTime := metav1.NewTime(defaultStartTime)
12+
// FIXME: this should be the git hash of the latest PCO
1013
gitHash := app.Status.Sync.Revision
11-
if app.Status.OperationState != nil &&
12-
app.Status.OperationState.Operation.Sync != nil &&
13-
app.Status.OperationState.Operation.Sync.Revision == gitHash {
14-
return app.Status.OperationState.StartedAt.Time, true
15-
} else if len(app.Status.History) != 0 {
16-
if app.Status.History.LastRevisionHistory().Revision == gitHash &&
17-
app.Status.History.LastRevisionHistory().DeployStartedAt != nil {
18-
startTime := *app.Status.History.LastRevisionHistory().DeployStartedAt
19-
return startTime.Time, true
14+
if app.Status.OperationState != nil {
15+
startTime = app.Status.OperationState.StartedAt
16+
} else if app.Status.History != nil {
17+
for _, history := range app.Status.History {
18+
if history.Revision == gitHash {
19+
startTime = *history.DeployStartedAt
20+
}
2021
}
2122
}
22-
return time.Time{}, false
23+
return startTime.Time
2324
}
2425

2526
// GetSyncFinishTime assumes that it is always called for calculating finish time of latest git hash
26-
func GetSyncFinishTime(app *v1alpha1.Application) (time.Time, bool) {
27+
func GetSyncFinishTime(app *v1alpha1.Application, defaultEndTime time.Time) time.Time {
28+
finishTime := metav1.NewTime(defaultEndTime)
29+
// FIXME: this should be the git hash of the latest PCO
2730
gitHash := app.Status.Sync.Revision
28-
if app.Status.OperationState != nil &&
29-
app.Status.OperationState.Operation.Sync != nil &&
30-
app.Status.OperationState.Operation.Sync.Revision == gitHash &&
31-
app.Status.OperationState.FinishedAt != nil {
32-
finishTime := *app.Status.OperationState.FinishedAt
33-
return finishTime.Time, true
34-
} else if len(app.Status.History) != 0 {
35-
if app.Status.History.LastRevisionHistory().Revision == gitHash &&
36-
app.Status.History.LastRevisionHistory().DeployStartedAt != nil {
37-
finishTime := *app.Status.History.LastRevisionHistory().DeployStartedAt
38-
return finishTime.Time, true
31+
if app.Status.OperationState != nil && app.Status.OperationState.FinishedAt != nil {
32+
finishTime = *app.Status.OperationState.FinishedAt
33+
} else if app.Status.History != nil {
34+
for _, history := range app.Status.History {
35+
if history.Revision == gitHash {
36+
finishTime = history.DeployedAt
37+
}
3938
}
4039
}
41-
return time.Time{}, false
40+
return finishTime.Time
4241
}

0 commit comments

Comments
 (0)