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: Auto trigger even if pre-cd fails #6338

Merged
merged 5 commits into from
Jan 31, 2025
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
1 change: 1 addition & 0 deletions pkg/eventProcessor/bean/workflowEventBean.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type CdStageCompleteEvent struct {
PluginRegistryArtifactDetails map[string][]string `json:"PluginRegistryArtifactDetails"`
PluginArtifacts *PluginArtifacts `json:"pluginArtifacts"`
IsArtifactUploaded bool `json:"isArtifactUploaded"`
IsFailed bool `json:"isFailed"`
}

type UserDeploymentRequest struct {
Expand Down
70 changes: 42 additions & 28 deletions pkg/eventProcessor/in/WorkflowEventProcessorService.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,47 +170,30 @@ func (impl *WorkflowEventProcessorImpl) SubscribeCDStageCompleteEvent() error {
return
}
wfr.IsArtifactUploaded = cdStageCompleteEvent.IsArtifactUploaded
if wfr.Status != string(v1alpha1.NodeSucceeded) {
if !slices.Contains(cdWorkflowModelBean.WfrTerminalStatusList, wfr.Status) {
impl.logger.Debugw("event received from ci runner, updating workflow runner status as succeeded", "savedWorkflowRunnerId", wfr.Id, "oldStatus", wfr.Status, "podStatus", wfr.PodStatus)
wfr.Status = string(v1alpha1.NodeSucceeded)
if cdStageCompleteEvent.IsFailed {
wfr.Status = string(v1alpha1.NodeFailed)
} else {
wfr.Status = string(v1alpha1.NodeSucceeded)
}
err = impl.cdWorkflowRunnerService.UpdateWfr(wfr, 1)
if err != nil {
impl.logger.Errorw("update cd-wf-runner failed for id ", "cdWfrId", wfr.Id, "err", err)
return
}

triggerContext := triggerBean.TriggerContext{
ReferenceId: pointer.String(msg.MsgId),
}
impl.handleCDStageCompleteEvent(triggerContext, cdStageCompleteEvent, wfr)
} else {
err = impl.cdWorkflowRunnerService.UpdateIsArtifactUploaded(wfr.Id, cdStageCompleteEvent.IsArtifactUploaded)
if err != nil {
impl.logger.Errorw("error in updating isArtifactUploaded", "cdWfrId", wfr.Id, "err", err)
return
}
}

triggerContext := triggerBean.TriggerContext{
ReferenceId: pointer.String(msg.MsgId),
}
if wfr.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
impl.logger.Debugw("received pre stage success event for workflow runner ", "wfId", strconv.Itoa(wfr.Id))
err = impl.workflowDagExecutor.HandlePreStageSuccessEvent(triggerContext, cdStageCompleteEvent)
if err != nil {
impl.logger.Errorw("deployment success event error", "err", err)
return
}
} else if wfr.WorkflowType == apiBean.CD_WORKFLOW_TYPE_POST {

pluginArtifacts := make(map[string][]string)
if cdStageCompleteEvent.PluginArtifacts != nil {
pluginArtifacts = cdStageCompleteEvent.PluginArtifacts.GetRegistryToUniqueContainerArtifactDataMapping()
}
globalUtil.MergeMaps(pluginArtifacts, cdStageCompleteEvent.PluginRegistryArtifactDetails)

impl.logger.Debugw("received post stage success event for workflow runner ", "wfId", strconv.Itoa(wfr.Id))
err = impl.workflowDagExecutor.HandlePostStageSuccessEvent(triggerContext, wfr, wfr.CdWorkflowId, cdStageCompleteEvent.CdPipelineId, cdStageCompleteEvent.TriggeredBy, pluginArtifacts)
if err != nil {
impl.logger.Errorw("deployment success event error", "err", err)
return
}
}
}

// add required logging here
Expand All @@ -233,6 +216,37 @@ func (impl *WorkflowEventProcessorImpl) SubscribeCDStageCompleteEvent() error {
return nil
}

func (impl *WorkflowEventProcessorImpl) handleCDStageCompleteEvent(triggerContext triggerBean.TriggerContext, cdStageCompleteEvent bean.CdStageCompleteEvent, wfr *cdWorkflowBean.CdWorkflowRunnerDto) {
if cdStageCompleteEvent.IsFailed {
impl.logger.Debugw("event received from ci runner, updating workflow runner status as failed, not taking any action", "savedWorkflowRunnerId", wfr.Id, "oldStatus", wfr.Status, "podStatus", wfr.PodStatus)
return
}

var err error
if wfr.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
impl.logger.Debugw("received pre stage success event for workflow runner ", "wfId", strconv.Itoa(wfr.Id))
err = impl.workflowDagExecutor.HandlePreStageSuccessEvent(triggerContext, cdStageCompleteEvent)
if err != nil {
impl.logger.Errorw("deployment success event error", "err", err)
return
}
} else if wfr.WorkflowType == apiBean.CD_WORKFLOW_TYPE_POST {
impl.logger.Debugw("received post stage success event for workflow runner ", "wfId", strconv.Itoa(wfr.Id))

pluginArtifacts := make(map[string][]string)
if cdStageCompleteEvent.PluginArtifacts != nil {
pluginArtifacts = cdStageCompleteEvent.PluginArtifacts.GetRegistryToUniqueContainerArtifactDataMapping()
}
globalUtil.MergeMaps(pluginArtifacts, cdStageCompleteEvent.PluginRegistryArtifactDetails)

err = impl.workflowDagExecutor.HandlePostStageSuccessEvent(triggerContext, wfr, wfr.CdWorkflowId, cdStageCompleteEvent.CdPipelineId, cdStageCompleteEvent.TriggeredBy, pluginArtifacts)
if err != nil {
impl.logger.Errorw("deployment success event error", "err", err)
return
}
}
}

func (impl *WorkflowEventProcessorImpl) SubscribeTriggerBulkAction() error {
callback := func(msg *model.PubSubMsg) {
cdWorkflow := new(pipelineConfig.CdWorkflow)
Expand Down