@@ -36,7 +36,7 @@ type WorkFlowStageStatusServiceImpl struct {
36
36
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
37
37
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
38
38
transactionManager sql.TransactionWrapper
39
- config * types.CiCdConfig
39
+ config * types.CiConfig
40
40
}
41
41
42
42
func NewWorkflowStageFlowStatusServiceImpl (logger * zap.SugaredLogger ,
@@ -52,11 +52,11 @@ func NewWorkflowStageFlowStatusServiceImpl(logger *zap.SugaredLogger,
52
52
cdWorkflowRepository : cdWorkflowRepository ,
53
53
transactionManager : transactionManager ,
54
54
}
55
- ciCdConfig , err := types .GetCiCdConfig ()
55
+ ciConfig , err := types .GetCiConfig ()
56
56
if err != nil {
57
57
return nil
58
58
}
59
- wfStageServiceImpl .config = ciCdConfig
59
+ wfStageServiceImpl .config = ciConfig
60
60
return wfStageServiceImpl
61
61
}
62
62
@@ -93,15 +93,15 @@ func (impl *WorkFlowStageStatusServiceImpl) getUpdatedPipelineStagesForWorkflow(
93
93
}
94
94
95
95
impl .logger .Infow ("step-1" , "wfId" , wfId , "wfType" , wfType , "wfStatus" , wfStatus , "currentWfDBstatus" , currentWfDBstatus , "podStatus" , podStatus , "currentPodStatus" , currentPodStatus , "message" , message )
96
- currentWorkflowStages , updatedPodStatus := impl .updatePodStages (currentWorkflowStages , podStatus , currentPodStatus , message , podName )
96
+ currentWorkflowStages , updatedPodStatus := impl .updatePodStages (currentWorkflowStages , podStatus , currentPodStatus , message , podName , wfStatus )
97
97
impl .logger .Infow ("step-2" , "updatedPodStatus" , updatedPodStatus , "updated pod stages" , currentWorkflowStages )
98
98
currentWorkflowStages , updatedWfStatus := impl .updateWorkflowStagesToDevtronStatus (currentWorkflowStages , wfStatus , currentWfDBstatus , message , podStatus )
99
99
impl .logger .Infow ("step-3" , "updatedWfStatus" , updatedWfStatus , "updatedPodStatus" , updatedPodStatus , "updated workflow stages" , currentWorkflowStages )
100
100
101
101
return currentWorkflowStages , updatedWfStatus , updatedPodStatus
102
102
}
103
103
104
- func (impl * WorkFlowStageStatusServiceImpl ) updatePodStages (currentWorkflowStages []* repository.WorkflowExecutionStage , podStatus string , currentPodStatus string , message string , podName string ) ([]* repository.WorkflowExecutionStage , string ) {
104
+ func (impl * WorkFlowStageStatusServiceImpl ) updatePodStages (currentWorkflowStages []* repository.WorkflowExecutionStage , podStatus string , currentPodStatus string , message string , podName string , wfStatus string ) ([]* repository.WorkflowExecutionStage , string ) {
105
105
updatedPodStatus := currentPodStatus
106
106
if ! slices .Contains (cdWorkflow .WfrTerminalStatusList , currentPodStatus ) {
107
107
updatedPodStatus = podStatus
@@ -147,9 +147,18 @@ func (impl *WorkFlowStageStatusServiceImpl) updatePodStages(currentWorkflowStage
147
147
}
148
148
default :
149
149
impl .logger .Errorw ("unknown pod status" , "podStatus" , podStatus , "message" , message )
150
- stage .Message = message
151
- stage .Status = bean2 .WORKFLOW_STAGE_STATUS_UNKNOWN
152
- stage .EndTime = time .Now ().Format (bean3 .LayoutRFC3339 )
150
+ if stage .Status == bean2 .WORKFLOW_STAGE_STATUS_NOT_STARTED {
151
+ extractedStatus := adapter .ConvertStatusToDevtronStatus (wfStatus , "" )
152
+ if extractedStatus .IsTerminal () {
153
+ stage .Status = extractedStatus
154
+ stage .EndTime = time .Now ().Format (bean3 .LayoutRFC3339 )
155
+ updatedPodStatus = wfStatus
156
+ }
157
+ } else {
158
+ stage .Message = message
159
+ stage .Status = bean2 .WORKFLOW_STAGE_STATUS_UNKNOWN
160
+ stage .EndTime = time .Now ().Format (bean3 .LayoutRFC3339 )
161
+ }
153
162
}
154
163
}
155
164
}
@@ -275,6 +284,24 @@ func (impl *WorkFlowStageStatusServiceImpl) updateWorkflowStagesToDevtronStatus(
275
284
}
276
285
}
277
286
}
287
+ if stage .StageName == bean2 .WORKFLOW_PREPARATION && ! stage .Status .IsTerminal () {
288
+ //assumption: once pod is running we don't internally do any extra operation which would call this function and simply update status accrording to kubewatch events
289
+ //that's why we are getting pod status as unknown because we don't explicity set pod status
290
+ //this is the case when our internal code has called to update status before actually scheduling pod
291
+ //update wf status as given in request, don't change that
292
+ updatedWfStatus = util .ComputeWorkflowStatus (currentWfDBstatus , wfStatus , "" )
293
+ extractedStatus := adapter .ConvertStatusToDevtronStatus (wfStatus , wfMessage )
294
+ if extractedStatus .IsTerminal () {
295
+ stage .Status = extractedStatus
296
+ stage .EndTime = time .Now ().Format (bean3 .LayoutRFC3339 )
297
+ if extractedStatus == bean2 .WORKFLOW_STAGE_STATUS_TIMEOUT {
298
+ updatedWfStatus = cdWorkflow .WorkflowTimedOut
299
+ }
300
+ if extractedStatus == bean2 .WORKFLOW_STAGE_STATUS_ABORTED {
301
+ updatedWfStatus = cdWorkflow .WorkflowCancel
302
+ }
303
+ }
304
+ }
278
305
}
279
306
}
280
307
0 commit comments