Skip to content

Commit d414d6f

Browse files
committed
handle failure cases before scheduling
1 parent f91859d commit d414d6f

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

pkg/deployment/trigger/devtronApps/PreStageTriggerService.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
2324
blob_storage "github.com/devtron-labs/common-lib/blob-storage"
2425
commonBean "github.com/devtron-labs/common-lib/workflow"
2526
bean2 "github.com/devtron-labs/devtron/api/bean"
@@ -251,6 +252,7 @@ func (impl *TriggerServiceImpl) createStartingWfAndRunner(request bean.TriggerRe
251252
WorkflowType: request.WorkflowType,
252253
ExecutorType: impl.config.GetWorkflowExecutorType(),
253254
Status: cdWorkflow.WorkflowStarting, // starting PreStage
255+
PodStatus: string(v1alpha1.NodePending),
254256
TriggeredBy: triggeredBy,
255257
StartedOn: triggeredAt,
256258
Namespace: request.RunStageInEnvNamespace,

pkg/pipeline/CiService.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"errors"
2222
"fmt"
23+
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
2324
"github.com/caarlos0/env"
2425
"github.com/devtron-labs/common-lib/utils"
2526
bean3 "github.com/devtron-labs/common-lib/utils/bean"
@@ -1149,6 +1150,7 @@ func (impl *CiServiceImpl) SaveCiWorkflowWithStage(wf *pipelineConfig.CiWorkflow
11491150
}()
11501151
if impl.config.EnableWorkflowExecutionStage {
11511152
wf.Status = cdWorkflow.WorkflowWaitingToStart
1153+
wf.PodStatus = string(v1alpha1.NodePending)
11521154
}
11531155
err = impl.ciWorkflowRepository.SaveWorkFlowWithTx(wf, tx)
11541156
if err != nil {

pkg/pipeline/workflowStatus/WorkflowStageStatusService.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type WorkFlowStageStatusServiceImpl struct {
3636
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
3737
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
3838
transactionManager sql.TransactionWrapper
39-
config *types.CiCdConfig
39+
config *types.CiConfig
4040
}
4141

4242
func NewWorkflowStageFlowStatusServiceImpl(logger *zap.SugaredLogger,
@@ -52,11 +52,11 @@ func NewWorkflowStageFlowStatusServiceImpl(logger *zap.SugaredLogger,
5252
cdWorkflowRepository: cdWorkflowRepository,
5353
transactionManager: transactionManager,
5454
}
55-
ciCdConfig, err := types.GetCiCdConfig()
55+
ciConfig, err := types.GetCiConfig()
5656
if err != nil {
5757
return nil
5858
}
59-
wfStageServiceImpl.config = ciCdConfig
59+
wfStageServiceImpl.config = ciConfig
6060
return wfStageServiceImpl
6161
}
6262

@@ -93,15 +93,15 @@ func (impl *WorkFlowStageStatusServiceImpl) getUpdatedPipelineStagesForWorkflow(
9393
}
9494

9595
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)
9797
impl.logger.Infow("step-2", "updatedPodStatus", updatedPodStatus, "updated pod stages", currentWorkflowStages)
9898
currentWorkflowStages, updatedWfStatus := impl.updateWorkflowStagesToDevtronStatus(currentWorkflowStages, wfStatus, currentWfDBstatus, message, podStatus)
9999
impl.logger.Infow("step-3", "updatedWfStatus", updatedWfStatus, "updatedPodStatus", updatedPodStatus, "updated workflow stages", currentWorkflowStages)
100100

101101
return currentWorkflowStages, updatedWfStatus, updatedPodStatus
102102
}
103103

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) {
105105
updatedPodStatus := currentPodStatus
106106
if !slices.Contains(cdWorkflow.WfrTerminalStatusList, currentPodStatus) {
107107
updatedPodStatus = podStatus
@@ -147,9 +147,18 @@ func (impl *WorkFlowStageStatusServiceImpl) updatePodStages(currentWorkflowStage
147147
}
148148
default:
149149
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+
}
153162
}
154163
}
155164
}
@@ -275,6 +284,24 @@ func (impl *WorkFlowStageStatusServiceImpl) updateWorkflowStagesToDevtronStatus(
275284
}
276285
}
277286
}
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+
}
278305
}
279306
}
280307

pkg/pipeline/workflowStatus/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func ComputeWorkflowStatus(currentWfDBstatus, wfStatus, stageStatus string) string {
99
updatedWfStatus := currentWfDBstatus
1010
if !slices.Contains(cdWorkflow.WfrTerminalStatusList, currentWfDBstatus) {
11-
if !slices.Contains(cdWorkflow.WfrTerminalStatusList, wfStatus) {
11+
if len(stageStatus) > 0 && !slices.Contains(cdWorkflow.WfrTerminalStatusList, wfStatus) {
1212
updatedWfStatus = stageStatus
1313
} else {
1414
updatedWfStatus = wfStatus

pkg/workflow/cd/CdWorkflowRunnerService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type CdWorkflowRunnerServiceImpl struct {
4444
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
4545
workflowStageService workflowStatus.WorkFlowStageStatusService
4646
transactionManager sql.TransactionWrapper
47-
config *types.CiCdConfig
47+
config *types.CiConfig
4848
}
4949

5050
func NewCdWorkflowRunnerServiceImpl(logger *zap.SugaredLogger,
@@ -57,11 +57,11 @@ func NewCdWorkflowRunnerServiceImpl(logger *zap.SugaredLogger,
5757
workflowStageService: workflowStageService,
5858
transactionManager: transactionManager,
5959
}
60-
ciCdConfig, err := types.GetCiCdConfig()
60+
ciConfig, err := types.GetCiConfig()
6161
if err != nil {
6262
return nil
6363
}
64-
impl.config = ciCdConfig
64+
impl.config = ciConfig
6565
return impl
6666
}
6767

0 commit comments

Comments
 (0)