Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 17 additions & 0 deletions api/helm-app/HelmAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
service2 "github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/EAMode"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -119,6 +120,10 @@ func (handler *HelmAppRestHandlerImpl) GetApplicationDetail(w http.ResponseWrite
//RBAC enforcer Ends
appdetail, err := handler.helmAppService.GetApplicationDetail(context.Background(), appIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -221,6 +226,10 @@ func (handler *HelmAppRestHandlerImpl) GetReleaseInfo(w http.ResponseWriter, r *
//RBAC enforcer Ends
releaseInfo, err := handler.helmAppService.GetValuesYaml(r.Context(), appIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -264,6 +273,10 @@ func (handler *HelmAppRestHandlerImpl) GetDesiredManifest(w http.ResponseWriter,
//RBAC enforcer Ends
res, err := handler.helmAppService.GetDesiredManifest(r.Context(), appIdentifier, desiredManifestRequest.Resource)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -321,6 +334,10 @@ func (handler *HelmAppRestHandlerImpl) DeleteApplication(w http.ResponseWriter,
res, err = handler.helmAppService.DeleteApplication(r.Context(), appIdentifier)
}
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down
5 changes: 5 additions & 0 deletions api/k8s/application/k8sApplicationRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/cluster"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/devtron-labs/devtron/pkg/k8s"
application2 "github.com/devtron-labs/devtron/pkg/k8s/application"
bean2 "github.com/devtron-labs/devtron/pkg/k8s/application/bean"
Expand Down Expand Up @@ -275,6 +276,10 @@ func (handler *K8sApplicationRestHandlerImpl) GetHostUrlsByBatch(w http.Response
//RBAC enforcer Ends
appDetail, err := handler.helmAppService.GetApplicationDetail(r.Context(), appIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down
2 changes: 2 additions & 0 deletions internal/errors/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func (r *ClientStatusCode) GetHttpStatusCodeForGivenGrpcCode() int {
return http.StatusRequestTimeout
case codes.Canceled:
return constants.HttpClientSideTimeout
case codes.PermissionDenied:
return http.StatusUnprocessableEntity
default:
return http.StatusInternalServerError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/bean"
commonBean "github.com/devtron-labs/devtron/pkg/deployment/gitOps/common/bean"
validationBean "github.com/devtron-labs/devtron/pkg/deployment/gitOps/validation/bean"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"net/http"
"time"

Expand Down Expand Up @@ -127,6 +128,10 @@ func (impl *EAModeDeploymentServiceImpl) InstallApp(installAppVersionRequest *ap

_, err = impl.helmAppService.InstallRelease(ctx, installAppVersionRequest.ClusterId, installReleaseRequest)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return installAppVersionRequest, err
}
return installAppVersionRequest, nil
Expand Down Expand Up @@ -156,6 +161,10 @@ func (impl *EAModeDeploymentServiceImpl) DeleteInstalledApp(ctx context.Context,
deleteResponse, err := impl.helmAppService.DeleteApplication(ctx, appIdentifier)
if err != nil {
impl.Logger.Errorw("error in deleting helm application", "error", err, "appIdentifier", appIdentifier)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return err
}
if deleteResponse == nil || !deleteResponse.GetSuccess() {
Expand All @@ -181,6 +190,10 @@ func (impl *EAModeDeploymentServiceImpl) RollbackRelease(ctx context.Context, in
helmAppDeploymentDetail, err := impl.helmAppService.GetDeploymentDetail(ctx, helmAppIdeltifier, deploymentVersion)
if err != nil {
impl.Logger.Errorw("Error in getting helm application deployment detail", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return installedApp, false, err
}
valuesYamlJson := helmAppDeploymentDetail.GetValuesYaml()
Expand All @@ -207,6 +220,12 @@ func (impl *EAModeDeploymentServiceImpl) GetDeploymentHistory(ctx context.Contex
ReleaseName: installedApp.AppName,
}
history, err := impl.helmAppService.GetDeploymentHistory(ctx, helmAppIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
}
return history, err
}

Expand Down Expand Up @@ -235,6 +254,10 @@ func (impl *EAModeDeploymentServiceImpl) GetDeploymentHistoryInfo(ctx context.Co
span.End()
if err != nil {
impl.Logger.Errorw("error in getting deployment detail", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/go-github/github"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/xanzy/go-gitlab"
"strconv"

//"github.com/xanzy/go-gitlab"
"net/http"
Expand Down Expand Up @@ -297,7 +298,8 @@ func (impl *FullModeDeploymentServiceImpl) getGitCommitConfig(installAppVersionR
return nil, err
}
if util.IsErrNoRows(err) {
return nil, fmt.Errorf("Invalid request! No InstalledApp found.")
apiErr := &util.ApiError{HttpStatusCode: http.StatusNotFound, Code: strconv.Itoa(http.StatusNotFound), InternalMessage: "Invalid request! No InstalledApp found.", UserMessage: "Invalid request! No InstalledApp found."}
return nil, apiErr
}
installAppVersionRequest.GitOpsRepoURL = InstalledApp.GitOpsRepoUrl
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/internal/util"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/go-pg/pg"
"net/http"
"regexp"
Expand Down Expand Up @@ -107,6 +108,10 @@ func (impl *InstalledAppResourceServiceImpl) findNotesForArgoApplication(install
notes, err = impl.helmAppService.GetNotes(context.Background(), installReleaseRequest)
if err != nil {
impl.logger.Errorw("error in fetching notes", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return notes, appName, err
}
_, err = impl.updateNotesForInstalledApp(installedAppId, notes)
Expand Down
35 changes: 27 additions & 8 deletions pkg/errors/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package errors

import (
util2 "github.com/devtron-labs/devtron/internal/util"
"google.golang.org/grpc/status"
"net/http"
"strconv"
"strings"
Expand All @@ -15,6 +16,7 @@ const (
NamespaceNotFoundErrorMsg = "namespace not found"
InvalidValueErrorMsg = "invalid value in manifest"
OperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress"
ForbiddenErrMsg = "forbidden"
)

var errorHttpStatusCodeMap = map[string]int{
Expand All @@ -24,18 +26,35 @@ var errorHttpStatusCodeMap = map[string]int{
ArrayStringMismatchErrorMsg: http.StatusFailedDependency,
InvalidValueErrorMsg: http.StatusFailedDependency,
OperationInProgressErrorMsg: http.StatusConflict,
//forbidden error from kubernetes would not be a parameter for us to mark a user forbidden to that resource or not,
//since this is not rbac from devtron, hence map it to StatusUnprocessableEntity
ForbiddenErrMsg: http.StatusUnprocessableEntity,
}

func ConvertToApiError(err error) *util2.ApiError {
for errMsg, statusCode := range errorHttpStatusCodeMap {
if strings.Contains(err.Error(), errMsg) {
return &util2.ApiError{
InternalMessage: err.Error(),
UserMessage: err.Error(),
HttpStatusCode: statusCode,
Code: strconv.Itoa(statusCode),
var apiError *util2.ApiError
if _, ok := status.FromError(err); ok {
clientCode, _ := util2.GetClientDetailedError(err)
httpStatusCode := clientCode.GetHttpStatusCodeForGivenGrpcCode()
apiError = &util2.ApiError{
HttpStatusCode: httpStatusCode,
Code: strconv.Itoa(httpStatusCode),
InternalMessage: err.Error(),
UserMessage: err.Error(),
}
} else {
// instead of iterating or making a map, think of a better implementations
for errMsg, statusCode := range errorHttpStatusCodeMap {
if strings.Contains(err.Error(), errMsg) {
apiError = &util2.ApiError{
InternalMessage: err.Error(),
UserMessage: err.Error(),
HttpStatusCode: statusCode,
Code: strconv.Itoa(statusCode),
}
}
}
}
return nil

return apiError
}
9 changes: 9 additions & 0 deletions pkg/k8s/application/k8sApplicationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
client "github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"io"
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
"net/http"
Expand Down Expand Up @@ -428,6 +429,10 @@ func (impl *K8sApplicationServiceImpl) ValidateResourceRequest(ctx context.Conte
app, err := impl.helmAppService.GetApplicationDetail(ctx, appIdentifier)
if err != nil {
impl.logger.Errorw("error in getting app detail", "err", err, "appDetails", appIdentifier)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return false, err
}
valid := false
Expand Down Expand Up @@ -1019,6 +1024,10 @@ func (impl *K8sApplicationServiceImpl) RecreateResource(ctx context.Context, req
manifestRes, err := impl.helmAppService.GetDesiredManifest(ctx, request.AppIdentifier, resourceIdentifier)
if err != nil {
impl.logger.Errorw("error in getting desired manifest for validation", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return nil, err
}
manifest, manifestOk := manifestRes.GetManifestOk()
Expand Down
9 changes: 9 additions & 0 deletions pkg/module/ModuleService.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
client "github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/internal/sql/repository/security"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
moduleRepo "github.com/devtron-labs/devtron/pkg/module/repo"
moduleUtil "github.com/devtron-labs/devtron/pkg/module/util"
"github.com/devtron-labs/devtron/pkg/server"
Expand Down Expand Up @@ -225,6 +226,10 @@ func (impl ModuleServiceImpl) handleModuleNotFoundStatus(moduleName string) (Mod
releaseInfo, err := impl.helmAppService.GetValuesYaml(context.Background(), devtronHelmAppIdentifier)
if err != nil {
impl.logger.Errorw("Error in getting values yaml for devtron operator helm release", "moduleName", moduleName, "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return ModuleStatusNotInstalled, moduleType, false, err
}
releaseValues := releaseInfo.MergedValues
Expand Down Expand Up @@ -426,6 +431,10 @@ func (impl ModuleServiceImpl) HandleModuleAction(userId int32, moduleName string
updateResponse, err := impl.helmAppService.UpdateApplicationWithChartInfoWithExtraValues(context.Background(), devtronHelmAppIdentifier, chartRepository, extraValues, extraValuesYamlUrl, true)
if err != nil {
impl.logger.Errorw("error in updating helm release ", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
module.Status = ModuleStatusInstallFailed
impl.moduleRepository.Update(module)
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions pkg/pipeline/AppDeploymentTypeChangeManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
commonBean "github.com/devtron-labs/devtron/pkg/deployment/gitOps/common/bean"
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/config"
bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/devtron-labs/devtron/pkg/eventProcessor/out"
bean2 "github.com/devtron-labs/devtron/pkg/eventProcessor/out/bean"
"github.com/juju/errors"
Expand Down Expand Up @@ -762,6 +763,10 @@ func (impl *AppDeploymentTypeChangeManagerImpl) deleteHelmApp(ctx context.Contex

if err != nil {
impl.logger.Errorw("error in deleting helm application", "error", err, "appIdentifier", appIdentifier)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return err
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/pipeline/DeploymentPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/git"
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics"
config2 "github.com/devtron-labs/devtron/pkg/deployment/providerConfig"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/devtron-labs/devtron/pkg/eventProcessor/out"
"github.com/devtron-labs/devtron/pkg/imageDigestPolicy"
bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
Expand Down Expand Up @@ -890,6 +891,10 @@ func (impl *CdPipelineConfigServiceImpl) DeleteHelmTypePipelineDeploymentApp(ctx
} else {
if err != nil {
impl.logger.Errorw("error in deleting helm application", "error", err, "appIdentifier", appIdentifier)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return err
}
if deleteResourceResponse == nil || !deleteResourceResponse.GetSuccess() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/ServerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
client "github.com/devtron-labs/devtron/api/helm-app/service"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
moduleRepo "github.com/devtron-labs/devtron/pkg/module/repo"
moduleUtil "github.com/devtron-labs/devtron/pkg/module/util"
serverBean "github.com/devtron-labs/devtron/pkg/server/bean"
Expand Down Expand Up @@ -78,6 +79,10 @@ func (impl ServerServiceImpl) GetServerInfo(showServerStatus bool) (*serverBean.
devtronAppDetail, err := impl.helmAppService.GetApplicationDetail(context.Background(), devtronHelmAppIdentifier)
if err != nil {
impl.logger.Errorw("error in getting devtron helm app release status ", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return nil, err
}

Expand Down Expand Up @@ -153,6 +158,10 @@ func (impl ServerServiceImpl) HandleServerAction(userId int32, serverActionReque
updateResponse, err := impl.helmAppService.UpdateApplicationWithChartInfoWithExtraValues(context.Background(), devtronHelmAppIdentifier, chartRepository, extraValues, extraValuesYamlUrl, true)
if err != nil {
impl.logger.Errorw("error in updating helm release ", "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return nil, err
}
if !updateResponse.GetSuccess() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/webhook/helm/WebhookHelmService.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
bean3 "github.com/devtron-labs/devtron/pkg/attributes/bean"
"github.com/devtron-labs/devtron/pkg/chartRepo"
"github.com/devtron-labs/devtron/pkg/cluster"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/go-pg/pg"
"go.uber.org/zap"
"net/http"
Expand Down Expand Up @@ -154,6 +155,10 @@ func (impl WebhookHelmServiceImpl) CreateOrUpdateHelmApplication(ctx context.Con
res, err := impl.helmAppService.InstallRelease(ctx, clusterId, installReleaseRequest)
if err != nil {
impl.logger.Errorw("Error in installing helm release", "appIdentifier", appIdentifier, "err", err)
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
return nil, common.InternalServerError, err.Error(), http.StatusInternalServerError
}
if !res.GetSuccess() {
Expand Down