Skip to content

Commit 0fc6d64

Browse files
fix: ignore kubelink errors in server startup (#5852) (#5854)
* fix: ignore error message got while checking devtron installation status * fix: correct error messaging for docker creds
1 parent 68934d7 commit 0fc6d64

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

api/helm-app/service/HelmAppService.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type HelmAppService interface {
8686
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *helmBean.AppIdentifier, chartRepository *gRPC.ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
8787
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
8888
GetNotes(ctx context.Context, request *gRPC.InstallReleaseRequest) (string, error)
89-
ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) bool
89+
ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) (bool, error)
9090
GetRevisionHistoryMaxValue(appType bean.SourceAppType) int32
9191
GetResourceTreeForExternalResources(ctx context.Context, clusterId int, clusterConfig *gRPC.ClusterConfig, resources []*gRPC.ExternalResourceDetail) (*gRPC.ResourceTreeResponse, error)
9292
CheckIfNsExistsForClusterIds(clusterIdToNsMap map[int]string) error
@@ -1022,13 +1022,13 @@ func (impl *HelmAppServiceImpl) GetNotes(ctx context.Context, request *gRPC.Inst
10221022
return notesTxt, err
10231023
}
10241024

1025-
func (impl *HelmAppServiceImpl) ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) bool {
1025+
func (impl *HelmAppServiceImpl) ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) (bool, error) {
10261026
response, err := impl.helmAppClient.ValidateOCIRegistry(ctx, OCIRegistryRequest)
10271027
if err != nil {
10281028
impl.logger.Errorw("error in fetching chart", "err", err)
1029-
return false
1029+
return false, err
10301030
}
1031-
return response.IsLoggedIn
1031+
return response.IsLoggedIn, nil
10321032
}
10331033

10341034
func (impl *HelmAppServiceImpl) DecodeAppId(appId string) (*helmBean.AppIdentifier, error) {

api/restHandler/DockerRegRestHandler.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/devtron-labs/devtron/api/restHandler/common"
2626
repository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
27-
"github.com/devtron-labs/devtron/internal/util"
2827
chartProviderService "github.com/devtron-labs/devtron/pkg/appStore/chartProvider"
2928
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
3029
"github.com/devtron-labs/devtron/pkg/auth/user"
@@ -233,13 +232,8 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri
233232
//RBAC enforcer Ends
234233

235234
// valid registry credentials from kubelink
236-
if isValid := impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); !isValid {
237-
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
238-
err = &util.ApiError{
239-
HttpStatusCode: http.StatusBadRequest,
240-
InternalMessage: "Invalid authentication credentials. Please verify.",
241-
UserMessage: "Invalid authentication credentials. Please verify.",
242-
}
235+
if err = impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); err != nil {
236+
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err)
243237
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
244238
return
245239
}
@@ -349,13 +343,8 @@ func (impl DockerRegRestHandlerImpl) ValidateDockerRegistryConfig(w http.Respons
349343
bean.Cert = existingStore.Cert
350344
}
351345
// valid registry credentials from kubelink
352-
if isValid := impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); !isValid {
353-
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
354-
err = &util.ApiError{
355-
HttpStatusCode: http.StatusBadRequest,
356-
InternalMessage: "Invalid authentication credentials. Please verify.",
357-
UserMessage: "Invalid authentication credentials. Please verify.",
358-
}
346+
if err = impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); err != nil {
347+
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err)
359348
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
360349
return
361350
}

pkg/pipeline/DockerRegistryConfig.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type DockerRegistryConfig interface {
4646
Delete(storeId string) (string, error)
4747
DeleteReg(bean *types.DockerArtifactStoreBean) error
4848
CheckInActiveDockerAccount(storeId string) (bool, error)
49-
ValidateRegistryCredentials(bean *types.DockerArtifactStoreBean) bool
49+
ValidateRegistryCredentials(bean *types.DockerArtifactStoreBean) error
5050
ConfigureOCIRegistry(bean *types.DockerArtifactStoreBean, isUpdate bool, userId int32, tx *pg.Tx) error
5151
CreateOrUpdateOCIRegistryConfig(ociRegistryConfig *repository.OCIRegistryConfig, userId int32, tx *pg.Tx) error
5252
FilterOCIRegistryConfigForSpecificRepoType(ociRegistryConfigList []*repository.OCIRegistryConfig, repositoryType string) *repository.OCIRegistryConfig
@@ -578,13 +578,8 @@ func (impl DockerRegistryConfigImpl) Update(bean *types.DockerArtifactStoreBean)
578578
bean.PluginId = existingStore.PluginId
579579

580580
store := NewDockerArtifactStore(bean, true, existingStore.CreatedOn, time.Now(), existingStore.CreatedBy, bean.User)
581-
if isValid := impl.ValidateRegistryCredentials(bean); !isValid {
582-
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
583-
err = &util.ApiError{
584-
HttpStatusCode: http.StatusBadRequest,
585-
InternalMessage: "Invalid authentication credentials. Please verify.",
586-
UserMessage: "Invalid authentication credentials. Please verify.",
587-
}
581+
if err = impl.ValidateRegistryCredentials(bean); err != nil {
582+
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err)
588583
return nil, err
589584
}
590585
err = impl.dockerArtifactStoreRepository.Update(store, tx)
@@ -888,12 +883,14 @@ func (impl DockerRegistryConfigImpl) CheckInActiveDockerAccount(storeId string)
888883
return exist, nil
889884
}
890885

891-
func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.DockerArtifactStoreBean) bool {
886+
const ociRegistryInvalidCredsMsg = "Invalid authentication credentials. Please verify."
887+
888+
func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.DockerArtifactStoreBean) error {
892889
if bean.IsPublic ||
893890
bean.RegistryType == repository.REGISTRYTYPE_GCR ||
894891
bean.RegistryType == repository.REGISTRYTYPE_ARTIFACT_REGISTRY ||
895892
bean.RegistryType == repository.REGISTRYTYPE_OTHER {
896-
return true
893+
return nil
897894
}
898895
request := &bean2.RegistryCredential{
899896
RegistryUrl: bean.RegistryURL,
@@ -906,5 +903,21 @@ func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.Doc
906903
IsPublic: bean.IsPublic,
907904
Connection: bean.Connection,
908905
}
909-
return impl.helmAppService.ValidateOCIRegistry(context.Background(), request)
906+
907+
isLoggedIn, err := impl.helmAppService.ValidateOCIRegistry(context.Background(), request)
908+
if err != nil {
909+
impl.logger.Errorw("error in fetching chart", "err", err)
910+
return util.NewApiError().
911+
WithUserMessage("error in validating oci registry").
912+
WithInternalMessage(err.Error()).
913+
WithHttpStatusCode(http.StatusInternalServerError)
914+
}
915+
if !isLoggedIn {
916+
return util.NewApiError().
917+
WithUserMessage(ociRegistryInvalidCredsMsg).
918+
WithInternalMessage(ociRegistryInvalidCredsMsg).
919+
WithHttpStatusCode(http.StatusBadRequest)
920+
}
921+
922+
return nil
910923
}

pkg/server/ServerCacheService.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve
6363
// check if the release is installed or not
6464
isDevtronHelmReleaseInstalled, err := impl.helmAppService.IsReleaseInstalled(context.Background(), &appIdentifier)
6565
if err != nil {
66-
log.Println("not able to check if the devtron helm release exists or not.", "error", err)
67-
return nil, err
66+
logger.Errorw("not able to check if the devtron helm release exists or not.", "error", err)
67+
// return nil, err
68+
// not returning the error as it will bring down orchestrator
6869
}
6970

7071
// if not installed, treat it as OSS kubectl user

0 commit comments

Comments
 (0)