Skip to content

Commit

Permalink
Merge pull request #48 from devtron-labs/expose-with-grpc
Browse files Browse the repository at this point in the history
introduces some minor refac around error handling
  • Loading branch information
prakash100198 authored Nov 17, 2024
2 parents f445433 + 623f1a9 commit 58fcf35
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/api/GrpcHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewGrpcHandlerImpl(
}

func (impl *GrpcHandlerImpl) GetClusterUpgradeSummaryValidationResult(ctx context.Context, request *grpc.ClusterUpgradeRequest) (*grpc.ClusterUpgradeResponse, error) {
impl.logger.Infow("scan cluster resources compatibility for k8s version upgrade request", "request", request)
impl.logger.Infow("scan cluster resources compatibility for k8s version upgrade request", "clusterId", request.ClusterConfig.ClusterId, "clusterName", request.ClusterConfig.ClusterName, "serverUrl", request.ClusterConfig.ApiServerUrl)
summaryValidationResult, err := impl.clusterUpgradeReadService.GetClusterUpgradeSummaryValidationResult(request.TargetK8SVersion, request.ClusterConfig)
if err != nil {
impl.logger.Errorw("error in getting cluster upgrade summary validation result", "targetK8sVersion", request.TargetK8SVersion, "err", err)
Expand Down
5 changes: 3 additions & 2 deletions app/service/ClusterUpgradeReadService.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/devtron-labs/silver-surfer/app/grpc"
"github.com/devtron-labs/silver-surfer/kubedd"
"github.com/devtron-labs/silver-surfer/pkg"
errors2 "github.com/devtron-labs/silver-surfer/pkg/errors"
"go.uber.org/zap"
"k8s.io/client-go/rest"
)
Expand Down Expand Up @@ -45,8 +46,8 @@ func (impl *ClusterUpgradeReadServiceImpl) GetClusterUpgradeSummaryValidationRes
results, err := kubedd.ValidateCluster(cluster, &pkg.Config{TargetKubernetesVersion: targetK8sVersion})
if err != nil {
impl.logger.Errorw("error in ValidateCluster", "err", err)
if err.Error() == fmt.Sprintf(pkg.OpenApiSpecNotFoundError, targetK8sVersion) {
return nil, errors.New(fmt.Sprintf(pkg.OpenApiSpecNotFoundError, targetK8sVersion))
if errors.Is(err, errors2.ErrOpenApiSpecNotFound) {
return nil, errors.New(fmt.Sprintf(errors2.OpenApiSpecNotFoundError, targetK8sVersion))
}
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/K8sSchemaParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package pkg
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/devtron-labs/silver-surfer/pkg/errors"
"github.com/getkin/kin-openapi/openapi2"
"github.com/getkin/kin-openapi/openapi2conv"
"github.com/getkin/kin-openapi/openapi3"
Expand Down Expand Up @@ -116,7 +116,7 @@ func (k *kubeCheckerImpl) downloadFile(releaseVersion string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
return []byte{}, errors.New(fmt.Sprintf(OpenApiSpecNotFoundError, releaseVersion))
return []byte{}, errors.ErrOpenApiSpecNotFound
}
var out bytes.Buffer
_, err = io.Copy(&out, resp.Body)
Expand Down
2 changes: 0 additions & 2 deletions pkg/Util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
const (
gvFormat = "%s/%s"
gvkFormat = "%s/%s/%s"

OpenApiSpecNotFoundError = "openapi-spec not found for the k8s version %s"
)

func getKeyForGV(msg json.RawMessage) (string, error) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/errors/Errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package errors

import (
"errors"
)

const OpenApiSpecNotFoundError = "openapi-spec not found for the k8s version %s"

var ErrOpenApiSpecNotFound = errors.New(OpenApiSpecNotFoundError)

0 comments on commit 58fcf35

Please sign in to comment.