diff --git a/api/router/pubsub/ApplicationStatusHandler.go b/api/router/pubsub/ApplicationStatusHandler.go index 45964c5114..b02ab088cc 100644 --- a/api/router/pubsub/ApplicationStatusHandler.go +++ b/api/router/pubsub/ApplicationStatusHandler.go @@ -240,7 +240,7 @@ func (impl *ApplicationStatusHandlerImpl) updateArgoAppDeleteStatus(app *v1alpha } } else { // devtron app - err = impl.pipelineBuilder.DeleteCdPipeline(&pipeline, context.Background(), true, false, 0) + err = impl.pipelineBuilder.DeleteCdPipeline(&pipeline, context.Background(), true, false, 1) if err != nil { impl.logger.Errorw("error in deleting cd pipeline", "err", err) return err diff --git a/internal/sql/repository/pipelineConfig/PipelineRepository.go b/internal/sql/repository/pipelineConfig/PipelineRepository.go index e9226c3d3e..33d1aae7f5 100644 --- a/internal/sql/repository/pipelineConfig/PipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/PipelineRepository.go @@ -67,7 +67,7 @@ type PipelineRepository interface { Save(pipeline []*Pipeline, tx *pg.Tx) error Update(pipeline *Pipeline, tx *pg.Tx) error FindActiveByAppId(appId int) (pipelines []*Pipeline, err error) - Delete(id int, tx *pg.Tx) error + Delete(id int, userId int32, tx *pg.Tx) error FindByName(pipelineName string) (pipeline *Pipeline, err error) PipelineExists(pipelineName string) (bool, error) FindById(id int) (pipeline *Pipeline, err error) @@ -248,9 +248,10 @@ func (impl PipelineRepositoryImpl) FindActiveByAppIdAndEnvironmentIdV2() (pipeli return pipelines, err } -func (impl PipelineRepositoryImpl) Delete(id int, tx *pg.Tx) error { +func (impl PipelineRepositoryImpl) Delete(id int, userId int32, tx *pg.Tx) error { pipeline := &Pipeline{} - r, err := tx.Model(pipeline).Set("deleted =?", true).Set("deployment_app_created =?", false).Where("id =?", id).Update() + r, err := tx.Model(pipeline).Set("deleted =?", true).Set("deployment_app_created =?", false). + Set("updated_on = ?", time.Now()).Set("updated_by = ?", userId).Where("id =?", id).Update() impl.logger.Debugw("update result", "r-affected", r.RowsAffected(), "r-return", r.RowsReturned(), "model", r.Model()) return err } diff --git a/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go b/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go index d06f803b33..00228d21a3 100644 --- a/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go @@ -15,7 +15,7 @@ type PipelineRepository struct { } // Delete provides a mock function with given fields: id, tx -func (_m *PipelineRepository) Delete(id int, tx *pg.Tx) error { +func (_m *PipelineRepository) Delete(id int, userId int32, tx *pg.Tx) error { ret := _m.Called(id, tx) var r0 error diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index 81a9dfe29d..ccfb24105c 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -67,7 +67,7 @@ type CiCdPipelineOrchestrator interface { CreateCDPipelines(pipelineRequest *bean.CDPipelineConfigObject, appId int, userId int32, tx *pg.Tx, appName string) (pipelineId int, err error) UpdateCDPipeline(pipelineRequest *bean.CDPipelineConfigObject, userId int32, tx *pg.Tx) (err error) DeleteCiPipeline(pipeline *pipelineConfig.CiPipeline, request *bean.CiPatchRequest, tx *pg.Tx) error - DeleteCdPipeline(pipelineId int, tx *pg.Tx) error + DeleteCdPipeline(pipelineId int, userId int32, tx *pg.Tx) error PatchMaterialValue(createRequest *bean.CiPipeline, userId int32, oldPipeline *pipelineConfig.CiPipeline) (*bean.CiPipeline, error) PipelineExists(name string) (bool, error) GetCdPipelinesForApp(appId int) (cdPipelines *bean.CdPipelines, err error) @@ -1175,6 +1175,9 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCDPipelines(pipelineRequest *bean impl.logger.Error(err) return 0, err } + + + env, err := impl.envRepository.FindById(pipelineRequest.EnvironmentId) if err != nil { impl.logger.Errorw("error in getting environment by id", "err", err) @@ -1290,8 +1293,8 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateCDPipeline(pipelineRequest *bean. return err } -func (impl CiCdPipelineOrchestratorImpl) DeleteCdPipeline(pipelineId int, tx *pg.Tx) error { - return impl.pipelineRepository.Delete(pipelineId, tx) +func (impl CiCdPipelineOrchestratorImpl) DeleteCdPipeline(pipelineId int, userId int32, tx *pg.Tx) error { + return impl.pipelineRepository.Delete(pipelineId, userId, tx) } func (impl CiCdPipelineOrchestratorImpl) PipelineExists(name string) (bool, error) { diff --git a/pkg/pipeline/PipelineBuilder.go b/pkg/pipeline/PipelineBuilder.go index 21fef665e6..b4ba364ea7 100644 --- a/pkg/pipeline/PipelineBuilder.go +++ b/pkg/pipeline/PipelineBuilder.go @@ -1854,7 +1854,7 @@ func (impl PipelineBuilderImpl) DeleteCdPipeline(pipeline *pipelineConfig.Pipeli } // Rollback tx on error. defer tx.Rollback() - if err = impl.ciCdPipelineOrchestrator.DeleteCdPipeline(pipeline.Id, tx); err != nil { + if err = impl.ciCdPipelineOrchestrator.DeleteCdPipeline(pipeline.Id, userId, tx); err != nil { impl.logger.Errorw("err in deleting pipeline from db", "id", pipeline, "err", err) return err } @@ -3843,7 +3843,7 @@ func (impl PipelineBuilderImpl) MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDelete } impl.logger.Warnw("app not found in argo, deleting from db ", "err", err) //make call to delete it from pipeline DB because it's ACD counterpart is deleted - err = impl.DeleteCdPipeline(pipeline, context.Background(), true, false, 0) + err = impl.DeleteCdPipeline(pipeline, context.Background(), true, false, 1) if err != nil { impl.logger.Errorw("error in deleting cd pipeline", "err", err) return acdAppFound, err