Skip to content

Commit 177520a

Browse files
committed
TerminateDanglingWorkflow func in systemworkflowexec and argoworkflowexec
1 parent 22302c8 commit 177520a

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

pkg/pipeline/CiHandler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,16 @@ func (impl *CiHandlerImpl) CancelBuild(workflowId int, forceAbort bool) (int, er
612612
RestConfig: restConfig,
613613
IsExt: isExt,
614614
Environment: env,
615-
ForceAbort: forceAbort,
616615
}
617616
// Terminate workflow
618617
err = impl.workflowService.TerminateWorkflow(cancelWfDtoRequest)
619618
if err != nil && forceAbort {
620619
impl.Logger.Errorw("error in terminating workflow, with force abort flag flag as true", "workflowName", workflow.Name, "err", err)
621-
//ignoring error in case of force abort later updating workflow with force abort
620+
err1 := impl.workflowService.TerminateDanglingWorkflows(cancelWfDtoRequest)
621+
if err1 != nil {
622+
impl.Logger.Errorw("error in terminating dangling workflows", "cancelWfDtoRequest", cancelWfDtoRequest, "err", err)
623+
return 0, err1
624+
}
622625
} else if err != nil && strings.Contains(err.Error(), "cannot find workflow") {
623626
return 0, &util.ApiError{Code: "200", HttpStatusCode: http.StatusBadRequest, UserMessage: err.Error()}
624627
} else if err != nil {

pkg/pipeline/WorkflowService.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type WorkflowService interface {
5252
// ListAllWorkflows(namespace string) (*v1alpha1.WorkflowList, error)
5353
// UpdateWorkflow(wf *v1alpha1.Workflow) (*v1alpha1.Workflow, error)
5454
TerminateWorkflow(cancelWfDtoRequest *types.CancelWfRequestDto) error
55+
TerminateDanglingWorkflows(cancelWfDtoRequest *types.CancelWfRequestDto) error
5556
}
5657

5758
type WorkflowServiceImpl struct {
@@ -373,6 +374,29 @@ func (impl *WorkflowServiceImpl) TerminateWorkflow(cancelWfDtoRequest *types.Can
373374
}
374375
return err
375376
}
377+
378+
func (impl *WorkflowServiceImpl) TerminateDanglingWorkflows(cancelWfDtoRequest *types.CancelWfRequestDto) error {
379+
impl.Logger.Debugw("terminating dangling wf", "name", cancelWfDtoRequest.Name)
380+
var err error
381+
if cancelWfDtoRequest.ExecutorType != "" {
382+
workflowExecutor := impl.getWorkflowExecutor(cancelWfDtoRequest.ExecutorType)
383+
if workflowExecutor == nil {
384+
return errors.New("workflow executor not found")
385+
}
386+
if cancelWfDtoRequest.RestConfig == nil {
387+
cancelWfDtoRequest.RestConfig = impl.config
388+
}
389+
err = workflowExecutor.TerminateWorkflow(cancelWfDtoRequest.Name, cancelWfDtoRequest.Namespace, cancelWfDtoRequest.RestConfig)
390+
} else {
391+
wfClient, err := impl.getWfClient(cancelWfDtoRequest.Environment, cancelWfDtoRequest.Namespace, cancelWfDtoRequest.IsExt)
392+
if err != nil {
393+
return err
394+
}
395+
err = util.TerminateWorkflow(context.Background(), wfClient, cancelWfDtoRequest.Name)
396+
}
397+
return err
398+
}
399+
376400
func (impl *WorkflowServiceImpl) getRuntimeEnvClientInstance(environment *repository.Environment) (v1alpha12.WorkflowInterface, error) {
377401
restConfig, err, _ := impl.k8sCommonService.GetRestConfigByClusterId(context.Background(), environment.ClusterId)
378402
if err != nil {

pkg/pipeline/executors/ArgoWorkflowExecutor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type WorkflowExecutor interface {
5959
TerminateWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) error
6060
GetWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) (*unstructured.UnstructuredList, error)
6161
GetWorkflowStatus(workflowName string, namespace string, clusterConfig *rest.Config) (*types.WorkflowStatus, error)
62+
TerminateDanglingWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) error
6263
}
6364

6465
type ArgoWorkflowExecutor interface {
@@ -89,6 +90,10 @@ func (impl *ArgoWorkflowExecutorImpl) TerminateWorkflow(workflowName string, nam
8990
return err
9091
}
9192

93+
func (impl *ArgoWorkflowExecutorImpl) TerminateDanglingWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) error {
94+
95+
}
96+
9297
func (impl *ArgoWorkflowExecutorImpl) ExecuteWorkflow(workflowTemplate bean.WorkflowTemplate) (*unstructured.UnstructuredList, error) {
9398

9499
entryPoint := workflowTemplate.WorkflowType

pkg/pipeline/executors/SystemWorkflowExecutor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func (impl *SystemWorkflowExecutorImpl) TerminateWorkflow(workflowName string, n
114114
return err
115115
}
116116

117+
func (impl *SystemWorkflowExecutorImpl) TerminateDanglingWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) error {
118+
119+
}
120+
117121
func (impl *SystemWorkflowExecutorImpl) GetWorkflow(workflowName string, namespace string, clusterConfig *rest.Config) (*unstructured.UnstructuredList, error) {
118122
templatesList := &unstructured.UnstructuredList{}
119123
_, clientset, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(clusterConfig)

0 commit comments

Comments
 (0)