Skip to content

Commit ba9c7a7

Browse files
authored
fix: encountering panic in application groups in build and deploy page (#5330)
1 parent e054f06 commit ba9c7a7

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

api/restHandler/app/appList/AppListingRestHandler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func (handler AppListingRestHandlerImpl) FetchAppDetails(w http.ResponseWriter,
547547
apiError, ok := err.(*util.ApiError)
548548
if ok && apiError != nil {
549549
if apiError.Code == constants.AppDetailResourceTreeNotFound && appDetail.DeploymentAppDeleteRequest == true {
550-
acdAppFound, _ := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
550+
acdAppFound, _ := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken, cdPipeline)
551551
if acdAppFound {
552552
common.WriteJsonResp(w, fmt.Errorf("unable to fetch resource tree"), nil, http.StatusInternalServerError)
553553
return
@@ -638,20 +638,20 @@ func (handler AppListingRestHandlerImpl) FetchResourceTree(w http.ResponseWriter
638638
resourceTree, err := handler.fetchResourceTree(w, r, appId, envId, acdToken, cdPipeline)
639639
if err != nil {
640640
handler.logger.Errorw("error in fetching resource tree", "err", err, "appId", appId, "envId", envId)
641-
handler.handleResourceTreeErrAndDeletePipelineIfNeeded(w, err, appId, envId, acdToken, cdPipeline)
641+
handler.handleResourceTreeErrAndDeletePipelineIfNeeded(w, err, acdToken, cdPipeline)
642642
return
643643
}
644644
common.WriteJsonResp(w, err, resourceTree, http.StatusOK)
645645
}
646646

647647
func (handler AppListingRestHandlerImpl) handleResourceTreeErrAndDeletePipelineIfNeeded(w http.ResponseWriter, err error,
648-
appId int, envId int, acdToken string, cdPipeline *pipelineConfig.Pipeline) {
648+
acdToken string, cdPipeline *pipelineConfig.Pipeline) {
649649
var apiError *util.ApiError
650650
ok := errors.As(err, &apiError)
651651
if cdPipeline.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_ACD {
652652
if ok && apiError != nil {
653653
if apiError.Code == constants.AppDetailResourceTreeNotFound && cdPipeline.DeploymentAppDeleteRequest == true && cdPipeline.DeploymentAppCreated == true {
654-
acdAppFound, appDeleteErr := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
654+
acdAppFound, appDeleteErr := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken, cdPipeline)
655655
if appDeleteErr != nil {
656656
apiError.UserMessage = constants.ErrorDeletingPipelineForDeletedArgoAppMsg
657657
common.WriteJsonResp(w, apiError, nil, http.StatusInternalServerError)

internal/sql/repository/pipelineConfig/PipelineRepository.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type PipelineRepository interface {
7575
Update(pipeline *Pipeline, tx *pg.Tx) error
7676
FindActiveByAppId(appId int) (pipelines []*Pipeline, err error)
7777
Delete(id int, userId int32, tx *pg.Tx) error
78+
MarkPartiallyDeleted(id int, userId int32, tx *pg.Tx) error
7879
FindByName(pipelineName string) (pipeline *Pipeline, err error)
7980
PipelineExists(pipelineName string) (bool, error)
8081
FindById(id int) (pipeline *Pipeline, err error)
@@ -88,7 +89,6 @@ type PipelineRepository interface {
8889
GetByEnvOverrideId(envOverrideId int) ([]Pipeline, error)
8990
GetByEnvOverrideIdAndEnvId(envOverrideId, envId int) (Pipeline, error)
9091
FindActiveByAppIdAndEnvironmentId(appId int, environmentId int) (pipelines []*Pipeline, err error)
91-
UndoDelete(id int) error
9292
UniqueAppEnvironmentPipelines() ([]*Pipeline, error)
9393
FindByCiPipelineId(ciPipelineId int) (pipelines []*Pipeline, err error)
9494
FindByParentCiPipelineId(ciPipelineId int) (pipelines []*Pipeline, err error)
@@ -278,11 +278,18 @@ func (impl PipelineRepositoryImpl) Delete(id int, userId int32, tx *pg.Tx) error
278278
return err
279279
}
280280

281-
func (impl PipelineRepositoryImpl) UndoDelete(id int) error {
281+
func (impl PipelineRepositoryImpl) MarkPartiallyDeleted(id int, userId int32, tx *pg.Tx) error {
282282
pipeline := &Pipeline{}
283-
_, err := impl.dbConnection.Model(pipeline).Set("deleted =?", false).Where("id =?", id).Update()
283+
_, err := tx.Model(pipeline).
284+
Set("deployment_app_delete_request = ?", true).
285+
Set("updated_on = ?", time.Now()).
286+
Set("updated_by = ?", userId).
287+
Where("deleted = ?", false).
288+
Where("id = ?", id).
289+
Update()
284290
return err
285291
}
292+
286293
func (impl PipelineRepositoryImpl) FindByName(pipelineName string) (pipeline *Pipeline, err error) {
287294
pipeline = &Pipeline{}
288295
err = impl.dbConnection.Model(pipeline).
@@ -664,6 +671,7 @@ func (impl PipelineRepositoryImpl) FindIdsByProjectIdsAndEnvironmentIds(projectI
664671
func (impl PipelineRepositoryImpl) GetArgoPipelineByArgoAppName(argoAppName string) (Pipeline, error) {
665672
var pipeline Pipeline
666673
err := impl.dbConnection.Model(&pipeline).
674+
Column("pipeline.*", "Environment").
667675
Where("deployment_app_name = ?", argoAppName).
668676
Where("deployment_app_type = ?", util.PIPELINE_DEPLOYMENT_TYPE_ACD).
669677
Where("deleted = ?", false).

pkg/pipeline/DeploymentPipelineConfigService.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type CdPipelineConfigService interface {
113113
GetBulkActionImpactedPipelines(dto *bean.CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, error) //no usage
114114
// IsGitOpsRequiredForCD : Determine if GitOps is required for CD based on the provided pipeline creation request
115115
IsGitOpsRequiredForCD(pipelineCreateRequest *bean.CdPipelines) bool
116-
MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId int, envId int, acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error)
116+
MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error)
117117
// GetEnvironmentListForAutocompleteFilter : lists environment for given configuration
118118
GetEnvironmentListForAutocompleteFilter(envName string, clusterIds []int, offset int, size int, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool), ctx context.Context) (*clutserBean.ResourceGroupingResponse, error)
119119
RegisterInACD(ctx context.Context, chartGitAttr *commonBean.ChartGitAttribute, userId int32) error
@@ -824,7 +824,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipeline(pipeline *pipelineConf
824824
if pipeline.DeploymentAppCreated == true {
825825
deploymentAppName := fmt.Sprintf("%s-%s", pipeline.App.AppName, pipeline.Environment.Name)
826826
if util.IsAcdApp(pipeline.DeploymentAppType) {
827-
if !deleteResponse.ClusterReachable {
827+
if !forceDelete && !deleteResponse.ClusterReachable {
828828
impl.logger.Errorw("cluster connection error", "err", clusterBean.ErrorInConnecting)
829829
if cascadeDelete {
830830
return deleteResponse, nil
@@ -1427,7 +1427,7 @@ func (impl *CdPipelineConfigServiceImpl) IsGitOpsRequiredForCD(pipelineCreateReq
14271427
return haveAtLeastOneGitOps
14281428
}
14291429

1430-
func (impl *CdPipelineConfigServiceImpl) MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId int, envId int, acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error) {
1430+
func (impl *CdPipelineConfigServiceImpl) MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error) {
14311431

14321432
acdAppFound := false
14331433
ctx := context.Background()
@@ -1985,7 +1985,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipelinePartial(pipeline *pipel
19851985
if pipeline.DeploymentAppCreated && !pipeline.DeploymentAppDeleteRequest {
19861986
deploymentAppName := fmt.Sprintf("%s-%s", pipeline.App.AppName, pipeline.Environment.Name)
19871987
if util.IsAcdApp(pipeline.DeploymentAppType) {
1988-
if !deleteResponse.ClusterReachable {
1988+
if !forceDelete && !deleteResponse.ClusterReachable {
19891989
impl.logger.Errorw("cluster connection error", "err", clusterBean.ErrorInConnecting)
19901990
if cascadeDelete {
19911991
return deleteResponse, nil
@@ -2018,10 +2018,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipelinePartial(pipeline *pipel
20182018
}
20192019
}
20202020
impl.logger.Infow("app deleted from argocd", "id", pipeline.Id, "pipelineName", pipeline.Name, "app", deploymentAppName)
2021-
pipeline.DeploymentAppDeleteRequest = true
2022-
pipeline.UpdatedOn = time.Now()
2023-
pipeline.UpdatedBy = userId
2024-
err = impl.pipelineRepository.Update(pipeline, tx)
2021+
err = impl.pipelineRepository.MarkPartiallyDeleted(pipeline.Id, userId, tx)
20252022
if err != nil {
20262023
impl.logger.Errorw("error in partially delete cd pipeline", "err", err)
20272024
return deleteResponse, err

0 commit comments

Comments
 (0)