Skip to content

Commit

Permalink
fix: Unable to abort pre-cd and post-cd workflow (#4121)
Browse files Browse the repository at this point in the history
* check for active ci_pipeline_material

* check for external cluster

* check for nil config

* move restConfig to cdHandler

* revert changes
  • Loading branch information
Ashish-devtron committed Oct 19, 2023
1 parent e0f091f commit cbe8383
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/go-pg/pg"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"k8s.io/client-go/rest"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -600,10 +601,13 @@ func (impl *CdHandlerImpl) CancelStage(workflowRunnerId int, userId int32) (int,
} else if workflowRunner.WorkflowType == POST {
isExtCluster = pipeline.RunPostStageInEnv
}
restConfig, err := impl.k8sUtil.GetRestConfigByCluster(clusterConfig)
if err != nil {
impl.Logger.Errorw("error in getting rest config by cluster id", "err", err)
return 0, err
var restConfig *rest.Config
if isExtCluster {
restConfig, err = impl.k8sUtil.GetRestConfigByCluster(clusterConfig)
if err != nil {
impl.Logger.Errorw("error in getting rest config by cluster id", "err", err)
return 0, err
}
}
// Terminate workflow
err = impl.workflowService.TerminateWorkflow(workflowRunner.ExecutorType, workflowRunner.Name, workflowRunner.Namespace, restConfig, isExtCluster, nil)
Expand Down
3 changes: 3 additions & 0 deletions pkg/pipeline/WorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ func (impl *WorkflowServiceImpl) TerminateWorkflow(executorType pipelineConfig.W
var err error
if executorType != "" {
workflowExecutor := impl.getWorkflowExecutor(executorType)
if restConfig == nil {
restConfig = impl.config
}
err = workflowExecutor.TerminateWorkflow(name, namespace, restConfig)
} else {
wfClient, err := impl.getWfClient(environment, namespace, isExt)
Expand Down

0 comments on commit cbe8383

Please sign in to comment.