Skip to content

fix: encountering panic in application groups in build and deploy page #5330

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

Merged
merged 2 commits into from
Jun 20, 2024
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
8 changes: 4 additions & 4 deletions api/restHandler/app/appList/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func (handler AppListingRestHandlerImpl) FetchAppDetails(w http.ResponseWriter,
apiError, ok := err.(*util.ApiError)
if ok && apiError != nil {
if apiError.Code == constants.AppDetailResourceTreeNotFound && appDetail.DeploymentAppDeleteRequest == true {
acdAppFound, _ := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
acdAppFound, _ := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken, cdPipeline)
if acdAppFound {
common.WriteJsonResp(w, fmt.Errorf("unable to fetch resource tree"), nil, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -638,20 +638,20 @@ func (handler AppListingRestHandlerImpl) FetchResourceTree(w http.ResponseWriter
resourceTree, err := handler.fetchResourceTree(w, r, appId, envId, acdToken, cdPipeline)
if err != nil {
handler.logger.Errorw("error in fetching resource tree", "err", err, "appId", appId, "envId", envId)
handler.handleResourceTreeErrAndDeletePipelineIfNeeded(w, err, appId, envId, acdToken, cdPipeline)
handler.handleResourceTreeErrAndDeletePipelineIfNeeded(w, err, acdToken, cdPipeline)
return
}
common.WriteJsonResp(w, err, resourceTree, http.StatusOK)
}

func (handler AppListingRestHandlerImpl) handleResourceTreeErrAndDeletePipelineIfNeeded(w http.ResponseWriter, err error,
appId int, envId int, acdToken string, cdPipeline *pipelineConfig.Pipeline) {
acdToken string, cdPipeline *pipelineConfig.Pipeline) {
var apiError *util.ApiError
ok := errors.As(err, &apiError)
if cdPipeline.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_ACD {
if ok && apiError != nil {
if apiError.Code == constants.AppDetailResourceTreeNotFound && cdPipeline.DeploymentAppDeleteRequest == true && cdPipeline.DeploymentAppCreated == true {
acdAppFound, appDeleteErr := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
acdAppFound, appDeleteErr := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken, cdPipeline)
if appDeleteErr != nil {
apiError.UserMessage = constants.ErrorDeletingPipelineForDeletedArgoAppMsg
common.WriteJsonResp(w, apiError, nil, http.StatusInternalServerError)
Expand Down
14 changes: 11 additions & 3 deletions internal/sql/repository/pipelineConfig/PipelineRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type PipelineRepository interface {
Update(pipeline *Pipeline, tx *pg.Tx) error
FindActiveByAppId(appId int) (pipelines []*Pipeline, err error)
Delete(id int, userId int32, tx *pg.Tx) error
MarkPartiallyDeleted(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)
Expand All @@ -88,7 +89,6 @@ type PipelineRepository interface {
GetByEnvOverrideId(envOverrideId int) ([]Pipeline, error)
GetByEnvOverrideIdAndEnvId(envOverrideId, envId int) (Pipeline, error)
FindActiveByAppIdAndEnvironmentId(appId int, environmentId int) (pipelines []*Pipeline, err error)
UndoDelete(id int) error
UniqueAppEnvironmentPipelines() ([]*Pipeline, error)
FindByCiPipelineId(ciPipelineId int) (pipelines []*Pipeline, err error)
FindByParentCiPipelineId(ciPipelineId int) (pipelines []*Pipeline, err error)
Expand Down Expand Up @@ -278,11 +278,18 @@ func (impl PipelineRepositoryImpl) Delete(id int, userId int32, tx *pg.Tx) error
return err
}

func (impl PipelineRepositoryImpl) UndoDelete(id int) error {
func (impl PipelineRepositoryImpl) MarkPartiallyDeleted(id int, userId int32, tx *pg.Tx) error {
pipeline := &Pipeline{}
_, err := impl.dbConnection.Model(pipeline).Set("deleted =?", false).Where("id =?", id).Update()
_, err := tx.Model(pipeline).
Set("deployment_app_delete_request = ?", true).
Set("updated_on = ?", time.Now()).
Set("updated_by = ?", userId).
Where("deleted = ?", false).
Where("id = ?", id).
Update()
return err
}

func (impl PipelineRepositoryImpl) FindByName(pipelineName string) (pipeline *Pipeline, err error) {
pipeline = &Pipeline{}
err = impl.dbConnection.Model(pipeline).
Expand Down Expand Up @@ -664,6 +671,7 @@ func (impl PipelineRepositoryImpl) FindIdsByProjectIdsAndEnvironmentIds(projectI
func (impl PipelineRepositoryImpl) GetArgoPipelineByArgoAppName(argoAppName string) (Pipeline, error) {
var pipeline Pipeline
err := impl.dbConnection.Model(&pipeline).
Column("pipeline.*", "Environment").
Where("deployment_app_name = ?", argoAppName).
Where("deployment_app_type = ?", util.PIPELINE_DEPLOYMENT_TYPE_ACD).
Where("deleted = ?", false).
Expand Down
13 changes: 5 additions & 8 deletions pkg/pipeline/DeploymentPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type CdPipelineConfigService interface {
GetBulkActionImpactedPipelines(dto *bean.CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, error) //no usage
// IsGitOpsRequiredForCD : Determine if GitOps is required for CD based on the provided pipeline creation request
IsGitOpsRequiredForCD(pipelineCreateRequest *bean.CdPipelines) bool
MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId int, envId int, acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error)
MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(acdToken string, pipeline *pipelineConfig.Pipeline) (bool, error)
// GetEnvironmentListForAutocompleteFilter : lists environment for given configuration
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)
RegisterInACD(ctx context.Context, chartGitAttr *commonBean.ChartGitAttribute, userId int32) error
Expand Down Expand Up @@ -824,7 +824,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipeline(pipeline *pipelineConf
if pipeline.DeploymentAppCreated == true {
deploymentAppName := fmt.Sprintf("%s-%s", pipeline.App.AppName, pipeline.Environment.Name)
if util.IsAcdApp(pipeline.DeploymentAppType) {
if !deleteResponse.ClusterReachable {
if !forceDelete && !deleteResponse.ClusterReachable {
impl.logger.Errorw("cluster connection error", "err", clusterBean.ErrorInConnecting)
if cascadeDelete {
return deleteResponse, nil
Expand Down Expand Up @@ -1427,7 +1427,7 @@ func (impl *CdPipelineConfigServiceImpl) IsGitOpsRequiredForCD(pipelineCreateReq
return haveAtLeastOneGitOps
}

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

acdAppFound := false
ctx := context.Background()
Expand Down Expand Up @@ -1985,7 +1985,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipelinePartial(pipeline *pipel
if pipeline.DeploymentAppCreated && !pipeline.DeploymentAppDeleteRequest {
deploymentAppName := fmt.Sprintf("%s-%s", pipeline.App.AppName, pipeline.Environment.Name)
if util.IsAcdApp(pipeline.DeploymentAppType) {
if !deleteResponse.ClusterReachable {
if !forceDelete && !deleteResponse.ClusterReachable {
impl.logger.Errorw("cluster connection error", "err", clusterBean.ErrorInConnecting)
if cascadeDelete {
return deleteResponse, nil
Expand Down Expand Up @@ -2018,10 +2018,7 @@ func (impl *CdPipelineConfigServiceImpl) DeleteCdPipelinePartial(pipeline *pipel
}
}
impl.logger.Infow("app deleted from argocd", "id", pipeline.Id, "pipelineName", pipeline.Name, "app", deploymentAppName)
pipeline.DeploymentAppDeleteRequest = true
pipeline.UpdatedOn = time.Now()
pipeline.UpdatedBy = userId
err = impl.pipelineRepository.Update(pipeline, tx)
err = impl.pipelineRepository.MarkPartiallyDeleted(pipeline.Id, userId, tx)
if err != nil {
impl.logger.Errorw("error in partially delete cd pipeline", "err", err)
return deleteResponse, err
Expand Down
Loading