-
Notifications
You must be signed in to change notification settings - Fork 554
feat: deployment pipeline partially delete. #2950
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
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
08618f3
wip
iamayushm 596188f
wip
iamayushm 694f703
added deployment app delete request flag for both cd pipeline and ins…
vikramdevtron 796b342
wip: adding handling if kubewatch delete status is lost
iamayushm ea8da67
Merge branch 'delete_acd_app_status' into acd-app-partially-delete
iamayushm 158c7aa
temp commit
iamayushm ba899f6
shifting code from temp branch to main branch
iamayushm bce5ea5
wip: temp change
iamayushm eef877f
wip: temp change
iamayushm 7847e83
Merge remote-tracking branch 'origin/acd-app-partially-delete' into a…
iamayushm 40d1cfb
migration scripts
iamayushm 7b8cd96
migration scripts
iamayushm d27ac8c
Merge branch 'main' into acd-app-partially-delete
iamayushm 896365a
migration scripts
iamayushm ad6e820
adding app delete check
iamayushm 24fff1a
adding deployment app created flag
iamayushm ef941b2
removing app delete check
iamayushm 094269a
refactoring and corner case handle
iamayushm b4a7f5e
reverting schemas
iamayushm f709052
wip: fixes after refactoring
iamayushm 28061db
updating migration scripts
iamayushm ffe9b2b
updating vendor file
iamayushm 3edac6f
adding back argocd file
iamayushm ff314fe
updating vendor
iamayushm ad44a3c
adding back asset folder
iamayushm b5a5520
Merge branch 'main' into acd-app-partially-delete
iamayushm e0ed134
fixing merge errors
iamayushm 658f89f
correcting sql script sequence no
iamayushm ca4fac6
skipping app status deletion if not found in database
iamayushm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ import ( | |
| openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient" | ||
| "github.com/devtron-labs/devtron/api/restHandler/common" | ||
| "github.com/devtron-labs/devtron/client/argocdServer/application" | ||
| "github.com/devtron-labs/devtron/internal/constants" | ||
| util2 "github.com/devtron-labs/devtron/internal/util" | ||
| appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean" | ||
| "github.com/devtron-labs/devtron/pkg/appStore/deployment/service" | ||
| "github.com/devtron-labs/devtron/pkg/cluster" | ||
|
|
@@ -34,6 +36,7 @@ import ( | |
| "github.com/devtron-labs/devtron/util/argo" | ||
| "github.com/devtron-labs/devtron/util/rbac" | ||
| "github.com/devtron-labs/devtron/util/response" | ||
| "github.com/go-pg/pg" | ||
| "github.com/gorilla/mux" | ||
| "go.uber.org/zap" | ||
| "gopkg.in/go-playground/validator.v9" | ||
|
|
@@ -401,6 +404,12 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w htt | |
| } | ||
| handler.Logger.Infow("request payload, FetchAppDetailsForInstalledApp, app store", "installedAppId", installedAppId, "envId", envId) | ||
|
|
||
| err = handler.installedAppService.CheckAppExistsByInstalledAppId(installedAppId) | ||
| if err == pg.ErrNoRows { | ||
| common.WriteJsonResp(w, err, "App not found in database", http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| appDetail, err := handler.installedAppService.FindAppDetailsForAppstoreApplication(installedAppId, envId) | ||
| if err != nil { | ||
| handler.Logger.Errorw("service err, FetchAppDetailsForInstalledApp, app store", "err", err, "installedAppId", installedAppId, "envId", envId) | ||
|
|
@@ -425,16 +434,33 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w htt | |
| } | ||
| //rback block ends here | ||
| if len(appDetail.AppName) > 0 && len(appDetail.EnvironmentName) > 0 { | ||
| handler.fetchResourceTree(w, r, &appDetail) | ||
| err = handler.fetchResourceTree(w, r, &appDetail) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move this logic at service layer |
||
| if appDetail.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD { | ||
| apiError, ok := err.(*util2.ApiError) | ||
| if ok && apiError != nil { | ||
| if apiError.Code == constants.AppDetailResourceTreeNotFound && appDetail.DeploymentAppDeleteRequest == true { | ||
| err = handler.installedAppService.MarkGitOpsInstalledAppsDeletedIfArgoAppIsDeleted(installedAppId, envId) | ||
| appDeleteErr, appDeleteErrOk := err.(*util2.ApiError) | ||
| if appDeleteErrOk && appDeleteErr != nil { | ||
| common.WriteJsonResp(w, fmt.Errorf(appDeleteErr.InternalMessage), nil, appDeleteErr.HttpStatusCode) | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } else if err != nil { | ||
| common.WriteJsonResp(w, fmt.Errorf("error in fetching resource tree"), nil, http.StatusInternalServerError) | ||
| } | ||
|
|
||
| } else { | ||
| appDetail.ResourceTree = map[string]interface{}{} | ||
| handler.Logger.Warnw("appName and envName not found - avoiding resource tree call", "app", appDetail.AppName, "env", appDetail.EnvironmentName) | ||
| } | ||
| common.WriteJsonResp(w, err, appDetail, http.StatusOK) | ||
| common.WriteJsonResp(w, nil, appDetail, http.StatusOK) | ||
| } | ||
|
|
||
| func (handler *InstalledAppRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, appDetail *bean2.AppDetailContainer) { | ||
| func (handler *InstalledAppRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, appDetail *bean2.AppDetailContainer) error { | ||
| ctx := r.Context() | ||
| cn, _ := w.(http.CloseNotifier) | ||
| handler.installedAppService.FetchResourceTree(ctx, cn, appDetail) | ||
| _, err := handler.installedAppService.FetchResourceTree(ctx, cn, appDetail) | ||
| return err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ import ( | |
| "github.com/devtron-labs/devtron/util/argo" | ||
| "github.com/devtron-labs/devtron/util/k8s" | ||
| "github.com/devtron-labs/devtron/util/rbac" | ||
| "github.com/go-pg/pg" | ||
| "github.com/gorilla/mux" | ||
| "go.opentelemetry.io/otel" | ||
| "go.uber.org/zap" | ||
|
|
@@ -355,6 +356,20 @@ func (handler AppListingRestHandlerImpl) FetchAppDetails(w http.ResponseWriter, | |
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| pipelines, err := handler.pipelineRepository.FindActiveByAppIdAndEnvironmentId(appId, envId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have to move this logic in service |
||
| if err == pg.ErrNoRows { | ||
| common.WriteJsonResp(w, err, "pipeline Not found in database", http.StatusNotFound) | ||
| return | ||
| } | ||
| if len(pipelines) == 0 { | ||
| common.WriteJsonResp(w, fmt.Errorf("app deleted"), nil, http.StatusNotFound) | ||
| return | ||
| } | ||
| if len(pipelines) != 1 { | ||
| common.WriteJsonResp(w, err, "multiple pipelines found for an envId", http.StatusBadRequest) | ||
| return | ||
| } | ||
| cdPipeline := pipelines[0] | ||
| appDetail, err := handler.appListingService.FetchAppDetails(r.Context(), appId, envId) | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, FetchAppDetails", "err", err, "appId", appId, "envId", envId) | ||
|
|
@@ -367,7 +382,31 @@ func (handler AppListingRestHandlerImpl) FetchAppDetails(w http.ResponseWriter, | |
| common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
| appDetail = handler.fetchResourceTree(w, r, appId, envId, appDetail) | ||
| acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken() | ||
| if err != nil { | ||
| common.WriteJsonResp(w, fmt.Errorf("error in getting acd token"), nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| appDetail, err = handler.fetchResourceTree(w, r, appId, envId, appDetail, acdToken, cdPipeline) | ||
| if appDetail.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_ACD { | ||
| 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) | ||
| if acdAppFound { | ||
| common.WriteJsonResp(w, fmt.Errorf("unable to fetch resource tree"), nil, http.StatusInternalServerError) | ||
| return | ||
| } else { | ||
| common.WriteJsonResp(w, fmt.Errorf("app deleted"), nil, http.StatusNotFound) | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if err != nil { | ||
| common.WriteJsonResp(w, fmt.Errorf("unable to fetch resource tree"), nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, appDetail, http.StatusOK) | ||
| } | ||
|
|
||
|
|
@@ -624,7 +663,8 @@ func (handler AppListingRestHandlerImpl) RedirectToLinkouts(w http.ResponseWrite | |
| func (handler AppListingRestHandlerImpl) fetchResourceTreeFromInstallAppService(w http.ResponseWriter, r *http.Request, appDetail bean.AppDetailContainer) bean.AppDetailContainer { | ||
| rctx := r.Context() | ||
| cn, _ := w.(http.CloseNotifier) | ||
| return handler.installedAppService.FetchResourceTree(rctx, cn, &appDetail) | ||
| _, _ = handler.installedAppService.FetchResourceTree(rctx, cn, &appDetail) | ||
| return appDetail | ||
| } | ||
| func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWriter, r *http.Request) { | ||
| vars := r.URL.Query() | ||
|
|
@@ -659,6 +699,16 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite | |
| common.WriteJsonResp(w, fmt.Errorf("error in parsing envId : %s must be integer", envIdParam), nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| pipelines, err := handler.pipelineRepository.FindActiveByAppIdAndEnvironmentId(appId, envId) | ||
| if err == pg.ErrNoRows { | ||
| common.WriteJsonResp(w, err, "pipeline Not found in database", http.StatusNotFound) | ||
| return | ||
| } | ||
| if len(pipelines) != 1 { | ||
| common.WriteJsonResp(w, err, "multiple pipelines found for an envId", http.StatusBadRequest) | ||
| return | ||
| } | ||
| cdPipeline := pipelines[0] | ||
| appDetail, err, appId = handler.getAppDetails(r.Context(), appIdParam, installedAppIdParam, envId) | ||
| if err != nil { | ||
| handler.logger.Errorw("error occurred while getting app details", "appId", appIdParam, "installedAppId", installedAppIdParam, "envId", envId) | ||
|
|
@@ -686,7 +736,12 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite | |
| if installedAppIdParam != "" { | ||
| appDetail = handler.fetchResourceTreeFromInstallAppService(w, r, appDetail) | ||
| } else { | ||
| appDetail = handler.fetchResourceTree(w, r, appId, envId, appDetail) | ||
| acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken() | ||
| if err != nil { | ||
| common.WriteJsonResp(w, fmt.Errorf("error in getting acd token"), nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| appDetail, err = handler.fetchResourceTree(w, r, appId, envId, appDetail, acdToken, cdPipeline) | ||
| } | ||
|
|
||
| resourceTree := appDetail.ResourceTree | ||
|
|
@@ -737,20 +792,9 @@ func (handler AppListingRestHandlerImpl) getAppDetails(ctx context.Context, appI | |
| } | ||
|
|
||
| // TODO: move this to service | ||
| func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, appId int, envId int, appDetail bean.AppDetailContainer) bean.AppDetailContainer { | ||
| func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, appId int, envId int, appDetail bean.AppDetailContainer, acdToken string, cdPipeline *pipelineConfig.Pipeline) (bean.AppDetailContainer, error) { | ||
| if len(appDetail.AppName) > 0 && len(appDetail.EnvironmentName) > 0 && util.IsAcdApp(appDetail.DeploymentAppType) { | ||
| //RBAC enforcer Ends | ||
| cdPipelines, err := handler.pipelineRepository.FindActiveByAppIdAndEnvironmentId(appId, envId) | ||
| if err != nil { | ||
| handler.logger.Errorw("error in getting cdPipeline by appId and envId", "err", err, "appid", appId, "envId", envId) | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
| return appDetail | ||
| } | ||
| if len(cdPipelines) != 1 { | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
| return appDetail | ||
| } | ||
| cdPipeline := cdPipelines[0] | ||
| query := &application2.ResourcesQuery{ | ||
| ApplicationName: &cdPipeline.DeploymentAppName, | ||
| } | ||
|
|
@@ -765,12 +809,6 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter | |
| }(ctx.Done(), cn.CloseNotify()) | ||
| } | ||
| defer cancel() | ||
| acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken() | ||
| if err != nil { | ||
| handler.logger.Errorw("error in getting acd token", "err", err) | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
| return appDetail | ||
| } | ||
| ctx = context.WithValue(ctx, "token", acdToken) | ||
| start := time.Now() | ||
| resp, err := handler.application.ResourceTree(ctx, query) | ||
|
|
@@ -782,8 +820,7 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter | |
| InternalMessage: "app detail fetched, failed to get resource tree from acd", | ||
| UserMessage: "Error fetching detail, if you have recently created this deployment pipeline please try after sometime.", | ||
| } | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
| return appDetail | ||
| return appDetail, err | ||
| } | ||
| if resp.Status == string(health.HealthStatusHealthy) { | ||
| status, err := handler.appListingService.ISLastReleaseStopType(appId, envId) | ||
|
|
@@ -842,7 +879,7 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter | |
| appDetail.ResourceTree = map[string]interface{}{} | ||
| handler.logger.Warnw("appName and envName not found - avoiding resource tree call", "app", appDetail.AppName, "env", appDetail.EnvironmentName) | ||
| } | ||
| return appDetail | ||
| return appDetail, nil | ||
| } | ||
|
|
||
| func (handler AppListingRestHandlerImpl) ManualSyncAcdPipelineDeploymentStatus(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid this check in rest handler, handle it in service layer.