Skip to content
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

fix: 5xx 3.0 #4578

Merged
merged 37 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4ba7514
multiple 5xx fixes
prakash100198 Jan 18, 2024
8b251fb
Merge branch 'main' into error-5xx-3.0
prakash100198 Jan 22, 2024
31d1657
main merge
prakash100198 Jan 22, 2024
f71ae99
DeleteCiPipeline 5xx handled
prakash100198 Jan 22, 2024
886b02b
common lib version change with my changes
prakash100198 Jan 22, 2024
3c77ae7
cluster delete 5xx fix
prakash100198 Jan 22, 2024
8137dfc
revert some changes
prakash100198 Jan 22, 2024
78ed824
DrainNode 5xx handling at rest handler
prakash100198 Jan 22, 2024
5f020b0
DrainNode 5xx handling at when getting node name
prakash100198 Jan 22, 2024
4e2f60c
fix
prakash100198 Jan 22, 2024
f1f924a
revert
prakash100198 Jan 22, 2024
02838b5
minor fixes
prakash100198 Jan 22, 2024
63849c6
Merge branch 'main' into 5xx-3.0
prakash100198 Jan 22, 2024
fa3c65b
main merge
prakash100198 Jan 22, 2024
220b204
minor fixes
prakash100198 Jan 22, 2024
0f8a2c9
minor fixes in k8s capacity and app services
prakash100198 Jan 22, 2024
5d7c4ef
Merge branch 'main' into 5xx-3.0
prakash100198 Jan 22, 2024
9c1bc5f
go mod version
prakash100198 Jan 22, 2024
b618848
make fixes
prakash100198 Jan 22, 2024
6c7f74e
timeout error also introduced while fetching api-resources of a cluster
prakash100198 Jan 22, 2024
b79ca1b
fix
prakash100198 Jan 22, 2024
d58cfc6
cd-pipeline/patch cd delete req 5xx handled for cluster unreachable (…
prakash100198 Jan 22, 2024
2d13756
app already exist 5xx
prakash100198 Jan 23, 2024
3586765
code refactoring
prakash100198 Jan 23, 2024
6d80c4a
fix
prakash100198 Jan 23, 2024
c6dc9b1
fix
prakash100198 Jan 23, 2024
3de1ba6
removing code 200 from all util Api errors
prakash100198 Jan 23, 2024
9658a2e
Merge branch 'main' into 5xx-3.0
prakash100198 Jan 24, 2024
4c8dd31
fix
prakash100198 Jan 24, 2024
93238ce
minor fix
prakash100198 Feb 2, 2024
70744ce
merge main
prakash100198 Feb 2, 2024
069c1e7
merge main branch here
prakash100198 Feb 16, 2024
0ed1c51
wire fix
prakash100198 Feb 16, 2024
1f04e60
minor fixes
prakash100198 Feb 19, 2024
1aa86f6
Merge branch 'main' into 5xx-3.0
prakash100198 Feb 19, 2024
8975c2b
Merge branch 'main' into 5xx-3.0
prakash100198 Feb 20, 2024
886079b
Merge branch 'main' into 5xx-3.0
prakash100198 Feb 20, 2024
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
2 changes: 1 addition & 1 deletion api/argoApplication/wire_argoApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ var ArgoApplicationWireSet = wire.NewSet(

NewArgoApplicationRouterImpl,
wire.Bind(new(ArgoApplicationRouter), new(*ArgoApplicationRouterImpl)),
)
)
35 changes: 35 additions & 0 deletions api/helm-app/service/ClusterUtils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package service

import (
"strings"
)

const (
DaemonSetPodDeleteError = "cannot delete DaemonSet-managed Pods"
DnsLookupNoSuchHostError = "no such host"
TimeoutError = "timeout"
NotFound = "not found"
ConnectionRefused = "connection refused"
)

func IsClusterUnReachableError(err error) bool {
if strings.Contains(err.Error(), DnsLookupNoSuchHostError) || strings.Contains(err.Error(), TimeoutError) ||
strings.Contains(err.Error(), ConnectionRefused) {
return true
}
return false
}

func IsNodeNotFoundError(err error) bool {
if strings.Contains(err.Error(), NotFound) {
return true
}
return false
}

func IsDaemonSetPodDeleteError(err error) bool {
if strings.Contains(err.Error(), DaemonSetPodDeleteError) {
return true
}
return false
}
4 changes: 4 additions & 0 deletions api/helm-app/service/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ func (impl *HelmAppServiceImpl) checkIfNsExists(app *AppIdentifier) (bool, error
}
exists, err := impl.K8sUtil.CheckIfNsExists(app.Namespace, v12Client)
if err != nil {
if IsClusterUnReachableError(err) {
impl.logger.Errorw("k8s cluster unreachable", "err", err)
return false, &util.ApiError{HttpStatusCode: http.StatusUnprocessableEntity, UserMessage: err.Error()}
}
impl.logger.Errorw("error in checking if namespace exists or not", "error", err, "clusterConfig", config)
return false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (impl *AppStoreDeploymentServiceImpl) createAppForAppStore(createRequest *b
if app1 != nil && app1.Id > 0 {
impl.logger.Infow(" app already exists", "name", createRequest.AppName)
err = &util.ApiError{
HttpStatusCode: http.StatusBadRequest,
Code: constants.AppAlreadyExists.Code,
InternalMessage: "app already exists",
UserMessage: fmt.Sprintf("app already exists with name %s", createRequest.AppName),
Expand Down Expand Up @@ -351,6 +352,7 @@ func (impl *AppStoreDeploymentServiceImpl) createAppForAppStore(createRequest *b
return nil, err
}
err = &util.ApiError{
HttpStatusCode: http.StatusBadRequest,
Code: constants.AppAlreadyExists.Code,
InternalMessage: "app already exists",
UserMessage: fmt.Sprintf("app already exists with name %s", createRequest.AppName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/bean"
commonBean "github.com/devtron-labs/devtron/pkg/deployment/gitOps/common/bean"
"net/http"
"time"

openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
Expand Down Expand Up @@ -142,6 +143,10 @@ func (impl *EAModeDeploymentServiceImpl) DeleteInstalledApp(ctx context.Context,

isInstalled, err := impl.helmAppService.IsReleaseInstalled(ctx, appIdentifier)
if err != nil {
if client.IsClusterUnReachableError(err) {
impl.Logger.Errorw("k8s cluster unreachable", "err", err)
return &util.ApiError{HttpStatusCode: http.StatusUnprocessableEntity, UserMessage: err.Error()}
}
impl.Logger.Errorw("error in checking if helm release is installed or not", "error", err, "appIdentifier", appIdentifier)
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ func (impl *InstalledAppResourceServiceImpl) FetchChartNotes(installedAppId int,
installedApp, err := impl.installedAppRepository.FetchNotes(installedAppId)
if err != nil && err != pg.ErrNoRows {
return "", err
} else if err == pg.ErrNoRows {
impl.logger.Errorw("installed app not found or may have been deleted", "installedAppId", installedAppId, "envId", envId)
return "", &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "Installed app not found in database or may have been deleted", InternalMessage: err.Error()}
}
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/delete/DeleteServiceExtended.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/devtron-labs/devtron/internal/sql/repository/app"
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/internal/util"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
repository2 "github.com/devtron-labs/devtron/pkg/appStore/installedApp/repository"
"github.com/devtron-labs/devtron/pkg/chartRepo"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/devtron-labs/devtron/pkg/team"
"github.com/go-pg/pg"
"go.uber.org/zap"
"net/http"
)

type DeleteServiceExtendedImpl struct {
Expand Down Expand Up @@ -61,7 +63,7 @@ func (impl DeleteServiceExtendedImpl) DeleteCluster(deleteRequest *cluster.Clust
}
if len(env) > 0 {
impl.logger.Errorw("err in deleting cluster, found env in this cluster", "clusterName", deleteRequest.ClusterName, "err", err)
return fmt.Errorf(" Please delete all related environments before deleting this cluster")
return &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: " Please delete all related environments before deleting this cluster"}
}
err = impl.clusterService.DeleteFromDb(deleteRequest, userId)
if err != nil {
Expand Down Expand Up @@ -89,13 +91,13 @@ func (impl DeleteServiceExtendedImpl) DeleteEnvironment(deleteRequest *cluster.E
}
if len(installedApps) > 0 && len(pipelines) > 0 {
impl.logger.Errorw("err in deleting env, found cd pipelines and helm apps in this env", "envName", deleteRequest.Environment, "err", err)
return fmt.Errorf(" Please delete all related cd pipelines and helm apps before deleting this environment")
return &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: " Please delete all related cd pipelines and helm apps before deleting this environment"}
} else if len(installedApps) > 0 {
impl.logger.Errorw("err in deleting env, found helm apps in this env", "envName", deleteRequest.Environment, "err", err)
return fmt.Errorf(" Please delete all related helm apps before deleting this environment")
return &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: " Please delete all related helm apps before deleting this environment"}
} else if len(pipelines) > 0 {
impl.logger.Errorw("err in deleting env, found cd pipelines in this env", "envName", deleteRequest.Environment, "err", err)
return fmt.Errorf(" Please delete all related cd pipelines before deleting this environment")
return &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: " Please delete all related cd pipelines before deleting this environment"}
}

err = impl.environmentService.Delete(deleteRequest, userId)
Expand Down
4 changes: 4 additions & 0 deletions pkg/k8s/application/k8sApplicationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ func (impl *K8sApplicationServiceImpl) GetAllApiResourceGVKWithoutAuthorization(
}
allApiResources, err := impl.K8sUtil.GetApiResources(restConfig, bean3.LIST_VERB)
if err != nil {
if client.IsClusterUnReachableError(err) {
impl.logger.Errorw("k8s cluster unreachable", "err", err)
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: err.Error()}
}
return nil, err
}
// FILTER STARTS
Expand Down
18 changes: 18 additions & 0 deletions pkg/k8s/capacity/k8sCapacityService.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"github.com/devtron-labs/common-lib/utils"
k8s2 "github.com/devtron-labs/common-lib/utils/k8s"
client "github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/k8s"
application2 "github.com/devtron-labs/devtron/pkg/k8s/application"
Expand Down Expand Up @@ -95,6 +97,10 @@ func (impl *K8sCapacityServiceImpl) GetClusterCapacityDetail(ctx context.Context
clusterDetail := &bean.ClusterCapacityDetail{}
nodeList, err := impl.K8sUtil.GetNodesList(ctx, k8sClientSet)
if err != nil {
if client.IsClusterUnReachableError(err) {
impl.logger.Errorw("k8s cluster unreachable", "err", err)
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: err.Error()}
}
impl.logger.Errorw("error in getting node list", "err", err, "clusterId", cluster.Id)
return nil, err
}
Expand Down Expand Up @@ -234,6 +240,10 @@ func (impl *K8sCapacityServiceImpl) GetNodeCapacityDetailsListByCluster(ctx cont
}
nodeList, err := impl.K8sUtil.GetNodesList(ctx, k8sClientSet)
if err != nil {
if client.IsClusterUnReachableError(err) {
impl.logger.Errorw("k8s cluster unreachable", "err", err)
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: err.Error()}
}
impl.logger.Errorw("error in getting node list", "err", err, "clusterId", cluster.Id)
return nil, err
}
Expand Down Expand Up @@ -632,6 +642,10 @@ func (impl *K8sCapacityServiceImpl) DrainNode(ctx context.Context, request *bean
//get node
node, err := impl.K8sUtil.GetNodeByName(context.Background(), k8sClientSet, request.Name)
if err != nil {
if client.IsNodeNotFoundError(err) {
impl.logger.Errorw("node not found", "err", err, "nodeName", request.Name)
return respMessage, &util.ApiError{HttpStatusCode: http.StatusNotFound, UserMessage: err.Error()}
}
impl.logger.Errorw("error in getting node", "err", err)
return respMessage, err
}
Expand All @@ -646,6 +660,10 @@ func (impl *K8sCapacityServiceImpl) DrainNode(ctx context.Context, request *bean
request.NodeDrainHelper.K8sClientSet = k8sClientSet
err = impl.deleteOrEvictPods(request.Name, request.NodeDrainHelper)
if err != nil {
if client.IsDaemonSetPodDeleteError(err) {
impl.logger.Errorw("daemonSet-managed pods can't be deleted", "err", err, "nodeName", request.Name)
return respMessage, &util.ApiError{HttpStatusCode: http.StatusNotFound, UserMessage: err.Error()}
}
impl.logger.Errorw("error in deleting/evicting pods", "err", err, "nodeName", request.Name)
return respMessage, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/BuildPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/juju/errors"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -1991,6 +1992,7 @@ func (impl *CiPipelineConfigServiceImpl) DeleteCiPipeline(request *bean.CiPatchR
}
if len(workflowMapping) > 0 {
return nil, &util.ApiError{
HttpStatusCode: http.StatusBadRequest,
InternalMessage: "Please delete deployment pipelines for this workflow first and try again.",
UserDetailMessage: fmt.Sprintf("Please delete deployment pipelines for this workflow first and try again."),
UserMessage: fmt.Sprintf("Please delete deployment pipelines for this workflow first and try again.")}
Expand Down
6 changes: 3 additions & 3 deletions pkg/pipeline/CiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,11 @@ func (impl *CiHandlerImpl) CancelBuild(workflowId int, forceAbort bool) (int, er

// Terminate workflow
err = impl.workflowService.TerminateWorkflow(workflow.ExecutorType, workflow.Name, workflow.Namespace, restConfig, isExt, env)
if err != nil && !strings.Contains(err.Error(), "cannot find workflow") {
if err != nil && strings.Contains(err.Error(), "cannot find workflow") {
return 0, &util.ApiError{Code: "200", HttpStatusCode: http.StatusBadRequest, UserMessage: err.Error()}
} else if err != nil {
impl.Logger.Errorw("cannot terminate wf", "err", err)
return 0, err
} else if err != nil {
return 0, &util.ApiError{Code: "200", HttpStatusCode: 400, UserMessage: err.Error()}
}

workflow.Status = executors.WorkflowCancel
Expand Down
5 changes: 2 additions & 3 deletions pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
repository4 "github.com/devtron-labs/devtron/pkg/variables/repository"
util3 "github.com/devtron-labs/devtron/util"
"github.com/go-pg/pg"
"net/http"

"github.com/devtron-labs/common-lib/blob-storage"
client "github.com/devtron-labs/devtron/client/events"
Expand Down Expand Up @@ -209,9 +210,7 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)
variableSnapshot := prePostAndRefPluginResponse.VariableSnapshot

if len(preCiSteps) == 0 && isJob {
return 0, &util.ApiError{
UserMessage: "No tasks are configured in this job pipeline",
}
return 0, &util.ApiError{HttpStatusCode: http.StatusNotFound, UserMessage: "No tasks are configured in this job pipeline"}
}
savedCiWf, err := impl.saveNewWorkflow(pipeline, ciWorkflowConfig, trigger.CommitHashes, trigger.TriggeredBy, trigger.EnvironmentId, isJob, trigger.ReferenceCiWorkflowId)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourceQualifiers/ResourceQualifiersMappingDto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const (
Filter = 1
ImageDigest = 2
ImageDigestResourceId = -1 // for ImageDigest resource id will is constant unlike filter and variables
InfraProfile = 3
InfraProfile = 3
)

type QualifierMapping struct {
Expand Down
Loading