Skip to content
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
2 changes: 1 addition & 1 deletion chart-sync/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

toolchain go1.24.3

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c

require (
github.com/caarlos0/env v3.5.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions chart-sync/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155 h1:/hdnSB/SGOsiIKw9/BH9kg5eg/Ov60IQj8Gjc8cVWgE=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c h1:ZtYIPskOvOkdqU66dggJ1eUR7xoaAL5xhYliYm0iRww=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN6UX90KJc4HjyM=
Expand Down
4 changes: 2 additions & 2 deletions chart-sync/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ github.com/containerd/platforms
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/constants
github.com/devtron-labs/common-lib/fetchAllEnv
Expand Down Expand Up @@ -967,4 +967,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
sigs.k8s.io/yaml
sigs.k8s.io/yaml/goyaml.v2
sigs.k8s.io/yaml/goyaml.v3
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
2 changes: 1 addition & 1 deletion ci-runner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

toolchain go1.24.3

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c

require (
github.com/Knetic/govaluate v3.0.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions ci-runner/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155 h1:/hdnSB/SGOsiIKw9/BH9kg5eg/Ov60IQj8Gjc8cVWgE=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c h1:ZtYIPskOvOkdqU66dggJ1eUR7xoaAL5xhYliYm0iRww=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v28.1.1+incompatible h1:eyUemzeI45DY7eDPuwUcmDyDj1pM98oD5MdSpiItp8k=
Expand Down
4 changes: 2 additions & 2 deletions ci-runner/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ github.com/cncf/xds/go/xds/type/v3
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/blob-storage
github.com/devtron-labs/common-lib/constants
Expand Down Expand Up @@ -1194,4 +1194,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
## explicit; go 1.12
sigs.k8s.io/yaml
sigs.k8s.io/yaml/goyaml.v2
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
56 changes: 56 additions & 0 deletions common-lib/k8sResource/errors/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package errors

import (
"google.golang.org/grpc/codes"
)

// list of error strings from Helm. These are part of the errors we check for presence in Helm's error messages.
const (
ClusterUnreachableErrorMsg = "cluster unreachable"
CrdPreconditionErrorMsg = "ensure crds are installed first"
ArrayStringMismatchErrorMsg = "got array expected string"
NotFoundErrorMsg = "not found" //this is a generic type constant, an error could be namespace "ns1" not found or service "ser1" not found.
InvalidValueErrorMsg = "invalid value"
OperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress"
ForbiddenErrorMsg = "forbidden"
)

// list of internal errors, these errors are easy for the users to understand
const (
InternalClusterUnreachableErrorMsg = "cluster unreachable"
InternalOperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress"
)

type errorGrpcCodeTuple struct {
errorMsg string
grpcCode codes.Code
}

var helmErrorInternalErrorMap = map[string]errorGrpcCodeTuple{
ClusterUnreachableErrorMsg: {errorMsg: InternalClusterUnreachableErrorMsg, grpcCode: codes.DeadlineExceeded},
OperationInProgressErrorMsg: {errorMsg: InternalOperationInProgressErrorMsg, grpcCode: codes.FailedPrecondition},
}

var DynamicErrorMapping = map[string]codes.Code{
NotFoundErrorMsg: codes.NotFound,
ForbiddenErrorMsg: codes.PermissionDenied,
InvalidValueErrorMsg: codes.InvalidArgument,
ArrayStringMismatchErrorMsg: codes.InvalidArgument,
CrdPreconditionErrorMsg: codes.FailedPrecondition,
}
55 changes: 55 additions & 0 deletions common-lib/k8sResource/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package errors

import (
"google.golang.org/grpc/status"
"strings"
)

// ConvertHelmErrorToInternalError converts known error message from helm to internal error and also maps it with proper grpc code
func ConvertHelmErrorToInternalError(err error) error {
genericError := getInternalErrorForGenericErrorTypes(err)
if genericError != nil {
return genericError
}
var internalError error
for helmErrMsg, internalErr := range helmErrorInternalErrorMap {
if strings.Contains(err.Error(), helmErrMsg) {
internalError = status.New(internalErr.grpcCode, internalErr.errorMsg).Err()
}
}
return internalError
}

// getInternalErrorForGenericErrorTypes returns all those kinds of errors which are generic in nature and also dynamic, make sure to return all generic and dynamic errors from this func. instead of putting them in helmErrorInternalErrorMap
func getInternalErrorForGenericErrorTypes(err error) error {
/*
for example:-
1. if namespace is not found err is:- namespace "ns1" not found,
2. in case ingress class not found error is of type ingress class: IngressClass.networking.k8s.io "ingress1" not found,
3. when some resource is forbidden then err can be of many formats one of which is:- Unable to continue with install: could not get information about the resource Ingress "prakash-1-prakash-env3-ingress" in namespace "prakash-ns3": ingresses.networking.k8s.io "prakash-1-prakash-env3-ingress" is forbidden...
etc..
*/
for errorMsg, code := range DynamicErrorMapping {
if strings.Contains(strings.ToLower(err.Error()), errorMsg) {
return status.New(code, err.Error()).Err()
}
}

return nil
}
13 changes: 11 additions & 2 deletions common-lib/k8sResource/listChildObjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package k8sResource
import (
"context"
"errors"
customErr "github.com/devtron-labs/common-lib/k8sResource/errors"
k8sUtils "github.com/devtron-labs/common-lib/utils/k8s"
k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
coreV1 "k8s.io/api/core/v1"
errors2 "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -196,8 +198,15 @@ func (impl *K8sServiceImpl) getChildObject(client *dynamicClient.DynamicClient,
filterListStartTime := time.Now()
childrenObjectsList, k8sErr := childResourceClient.List(context.Background(), options)
if k8sErr != nil {
impl.logger.Errorw("error in getting child listObjects", filterObjRequest.GetLoggerMetadata("counter", counter, "timeTaken", time.Since(filterListStartTime).Seconds(), "err", k8sErr)...)
return nil, k8sErr
statusError, matched := k8sErr.(*errors2.StatusError)
if !matched || statusError.ErrStatus.Reason != metaV1.StatusReasonNotFound {
internalErr := customErr.ConvertHelmErrorToInternalError(k8sErr)
if internalErr != nil {
k8sErr = internalErr
}
impl.logger.Errorw("error in getting child listObjects", filterObjRequest.GetLoggerMetadata("counter", counter, "timeTaken", time.Since(filterListStartTime).Seconds(), "err", k8sErr)...)
return nil, k8sErr
}
}
impl.logger.Debugw("listing child objects", filterObjRequest.GetLoggerMetadata("counter", counter, "timeTaken", time.Since(filterListStartTime).Seconds())...)
filterObjRequest = filterObjRequest.WithListObjects(childrenObjectsList)
Expand Down
2 changes: 1 addition & 1 deletion git-sensor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

toolchain go1.24.3

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c

require (
github.com/caarlos0/env v3.5.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions git-sensor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155 h1:/hdnSB/SGOsiIKw9/BH9kg5eg/Ov60IQj8Gjc8cVWgE=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c h1:ZtYIPskOvOkdqU66dggJ1eUR7xoaAL5xhYliYm0iRww=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e/go.mod h1:1TqULGlTey+VNhAu/ag7NJuUvByJemkqodsc9L5PHJk=
github.com/docker/cli v28.1.1+incompatible h1:eyUemzeI45DY7eDPuwUcmDyDj1pM98oD5MdSpiItp8k=
Expand Down
4 changes: 2 additions & 2 deletions git-sensor/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ github.com/cyphar/filepath-securejoin
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/constants
github.com/devtron-labs/common-lib/fetchAllEnv
Expand Down Expand Up @@ -472,4 +472,4 @@ gopkg.in/yaml.v3
# mellium.im/sasl v0.3.2
## explicit; go 1.20
mellium.im/sasl
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
2 changes: 1 addition & 1 deletion image-scanner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ require (
mellium.im/sasl v0.3.2 // indirect
)

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
4 changes: 2 additions & 2 deletions image-scanner/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155 h1:/hdnSB/SGOsiIKw9/BH9kg5eg/Ov60IQj8Gjc8cVWgE=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c h1:ZtYIPskOvOkdqU66dggJ1eUR7xoaAL5xhYliYm0iRww=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
Expand Down
4 changes: 2 additions & 2 deletions image-scanner/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ github.com/cespare/xxhash/v2
github.com/coreos/clair/api/v3/clairpb
github.com/coreos/clair/database
github.com/coreos/clair/ext/versionfmt
# github.com/devtron-labs/common-lib v0.19.0 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib v0.19.0 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/async
github.com/devtron-labs/common-lib/constants
Expand Down Expand Up @@ -456,4 +456,4 @@ google.golang.org/protobuf/types/known/wrapperspb
# mellium.im/sasl v0.3.2
## explicit; go 1.20
mellium.im/sasl
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702074224-9bda00b1f155
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250704063028-ee904611f07c
37 changes: 1 addition & 36 deletions kubelink/error/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,7 @@

package error

import (
"google.golang.org/grpc/codes"
)

// list of error strings from Helm. These are part of the errors we check for presence in Helm's error messages.
const (
YAMLToJSONConversionError = "error converting YAML to JSON"
ClusterUnreachableErrorMsg = "cluster unreachable"
CrdPreconditionErrorMsg = "ensure crds are installed first"
ArrayStringMismatchErrorMsg = "got array expected string"
NotFoundErrorMsg = "not found" //this is a generic type constant, an error could be namespace "ns1" not found or service "ser1" not found.
InvalidValueErrorMsg = "invalid value"
OperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress"
ForbiddenErrorMsg = "forbidden"
)

// list of internal errors, these errors are easy for the users to understand
const (
InternalClusterUnreachableErrorMsg = "cluster unreachable"
InternalOperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress"
YAMLToJSONConversionError = "error converting YAML to JSON"
)

type errorGrpcCodeTuple struct {
errorMsg string
grpcCode codes.Code
}

var helmErrorInternalErrorMap = map[string]errorGrpcCodeTuple{
ClusterUnreachableErrorMsg: {errorMsg: InternalClusterUnreachableErrorMsg, grpcCode: codes.DeadlineExceeded},
OperationInProgressErrorMsg: {errorMsg: InternalOperationInProgressErrorMsg, grpcCode: codes.FailedPrecondition},
}

var DynamicErrorMapping = map[string]codes.Code{
NotFoundErrorMsg: codes.NotFound,
ForbiddenErrorMsg: codes.PermissionDenied,
InvalidValueErrorMsg: codes.InvalidArgument,
ArrayStringMismatchErrorMsg: codes.InvalidArgument,
CrdPreconditionErrorMsg: codes.FailedPrecondition,
}
33 changes: 2 additions & 31 deletions kubelink/error/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,10 @@
package error

import (
"google.golang.org/grpc/status"
"strings"
customErr "github.com/devtron-labs/common-lib/k8sResource/errors"
)

// ConvertHelmErrorToInternalError converts known error message from helm to internal error and also maps it with proper grpc code
func ConvertHelmErrorToInternalError(err error) error {
genericError := getInternalErrorForGenericErrorTypes(err)
if genericError != nil {
return genericError
}
var internalError error
for helmErrMsg, internalErr := range helmErrorInternalErrorMap {
if strings.Contains(err.Error(), helmErrMsg) {
internalError = status.New(internalErr.grpcCode, internalErr.errorMsg).Err()
}
}
return internalError
}

// getInternalErrorForGenericErrorTypes returns all those kinds of errors which are generic in nature and also dynamic, make sure to return all generic and dynamic errors from this func. instead of putting them in helmErrorInternalErrorMap
func getInternalErrorForGenericErrorTypes(err error) error {
/*
for example:-
1. if namespace is not found err is:- namespace "ns1" not found,
2. in case ingress class not found error is of type ingress class: IngressClass.networking.k8s.io "ingress1" not found,
3. when some resource is forbidden then err can be of many formats one of which is:- Unable to continue with install: could not get information about the resource Ingress "prakash-1-prakash-env3-ingress" in namespace "prakash-ns3": ingresses.networking.k8s.io "prakash-1-prakash-env3-ingress" is forbidden...
etc..
*/
for errorMsg, code := range DynamicErrorMapping {
if strings.Contains(strings.ToLower(err.Error()), errorMsg) {
return status.New(code, err.Error()).Err()
}
}

return nil
return customErr.ConvertHelmErrorToInternalError(err)
}
Loading