Skip to content
Merged
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
47 changes: 23 additions & 24 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/sync/common"
"github.com/caarlos0/env"
client2 "github.com/devtron-labs/devtron/api/helm-app"
"github.com/devtron-labs/devtron/pkg/chart"
Expand Down Expand Up @@ -520,39 +521,37 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
if err != nil {
impl.logger.Errorw("error in saving/updating timeline resources", "err", err, "cdWfrId", cdWfrId)
}
if app.Status.Sync.Status == v1alpha1.SyncStatusCodeSynced {
var kubectlApplySyncedTimeline *pipelineConfig.PipelineStatusTimeline
if app != nil && app.Status.OperationState != nil && app.Status.OperationState.Phase == common.OperationSucceeded {
timeline.Id = 0
timeline.Status = pipelineConfig.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
if app != nil && app.Status.OperationState != nil {
timeline.StatusDetail = app.Status.OperationState.Message
}
var currentTimeline *pipelineConfig.PipelineStatusTimeline
timeline.StatusDetail = app.Status.OperationState.Message
//checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
currentTimeline, err, isTimelineUpdated = impl.SavePipelineStatusTimelineIfNotAlreadyPresent(cdWfrId, timeline.Status, timeline)
kubectlApplySyncedTimeline, err, isTimelineUpdated = impl.SavePipelineStatusTimelineIfNotAlreadyPresent(cdWfrId, timeline.Status, timeline)
if err != nil {
impl.logger.Errorw("error in saving pipeline status timeline", "err", err)
return isTimelineUpdated, isTimelineTimedOut, err
}
impl.logger.Debugw("APP_STATUS_UPDATE_REQ", "stage", "APPLY_SYNCED", "app", app, "status", timeline.Status)
if currentTimeline.StatusTime.Before(app.Status.ReconciledAt.Time) {
haveNewTimeline := false
timeline.Id = 0
if app.Status.Health.Status == health.HealthStatusHealthy {
impl.logger.Infow("updating pipeline status timeline for healthy app", "app", app, "APP_TO_UPDATE", app.Name)
haveNewTimeline = true
timeline.Status = pipelineConfig.TIMELINE_STATUS_APP_HEALTHY
timeline.StatusDetail = "App status is Healthy."
}
if haveNewTimeline {
//not checking if this status is already present or not because already checked for terminal status existence earlier
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
if err != nil {
impl.logger.Errorw("error in creating timeline status", "err", err, "timeline", timeline)
return isTimelineUpdated, isTimelineTimedOut, err
}
isTimelineUpdated = true
impl.logger.Debugw("APP_STATUS_UPDATE_REQ", "stage", "terminal_status", "app", app, "status", timeline.Status)
}
if kubectlApplySyncedTimeline != nil && kubectlApplySyncedTimeline.Id > 0 && kubectlApplySyncedTimeline.StatusTime.Before(app.Status.ReconciledAt.Time) {
haveNewTimeline := false
timeline.Id = 0
if app.Status.Health.Status == health.HealthStatusHealthy {
impl.logger.Infow("updating pipeline status timeline for healthy app", "app", app, "APP_TO_UPDATE", app.Name)
haveNewTimeline = true
timeline.Status = pipelineConfig.TIMELINE_STATUS_APP_HEALTHY
timeline.StatusDetail = "App status is Healthy."
}
if haveNewTimeline {
//not checking if this status is already present or not because already checked for terminal status existence earlier
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
if err != nil {
impl.logger.Errorw("error in creating timeline status", "err", err, "timeline", timeline)
return isTimelineUpdated, isTimelineTimedOut, err
}
isTimelineUpdated = true
impl.logger.Debugw("APP_STATUS_UPDATE_REQ", "stage", "terminal_status", "app", app, "status", timeline.Status)
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (impl *CdHandlerImpl) UpdatePipelineTimelineAndStatusByLiveApplicationFetch
return err, isTimelineUpdated
}
} else {
if app == nil {
impl.Logger.Errorw("found empty argo application object", "appName", pipeline.DeploymentAppName)
return fmt.Errorf("found empty argo application object"), isTimelineUpdated
}
isSucceeded, isTimelineUpdated, err = impl.appService.UpdateDeploymentStatusForGitOpsCdPipelines(app, time.Now())
if err != nil {
impl.Logger.Errorw("error in updating deployment status for gitOps cd pipelines", "app", app)
Expand Down