Skip to content

Commit 0edddcc

Browse files
committed
some refactor after self review
1 parent 96301c5 commit 0edddcc

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

app/api/GrpcHandler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewGrpcHandlerImpl(
2525
}
2626

2727
func (impl *GrpcHandlerImpl) GetClusterUpgradeSummaryValidationResult(ctx context.Context, request *grpc.ClusterUpgradeRequest) (*grpc.ClusterUpgradeResponse, error) {
28-
impl.logger.Infow("scan cluster resources compatibility for k8s version upgrade request", "request", request)
28+
impl.logger.Infow("scan cluster resources compatibility for k8s version upgrade request", "clusterId", request.ClusterConfig.ClusterId, "clusterName", request.ClusterConfig.ClusterName, "serverUrl", request.ClusterConfig.ApiServerUrl)
2929
summaryValidationResult, err := impl.clusterUpgradeReadService.GetClusterUpgradeSummaryValidationResult(request.TargetK8SVersion, request.ClusterConfig)
3030
if err != nil {
3131
impl.logger.Errorw("error in getting cluster upgrade summary validation result", "targetK8sVersion", request.TargetK8SVersion, "err", err)

app/service/ClusterUpgradeReadService.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (impl *ClusterUpgradeReadServiceImpl) GetClusterUpgradeSummaryValidationRes
4545
results, err := kubedd.ValidateCluster(cluster, &pkg.Config{TargetKubernetesVersion: targetK8sVersion})
4646
if err != nil {
4747
impl.logger.Errorw("error in ValidateCluster", "err", err)
48-
if err.Error() == fmt.Sprintf(pkg.OpenApiSpecNotFoundError, targetK8sVersion) {
48+
if errors.Is(err, pkg.ErrOpenApiSpecNotFound) {
4949
return nil, errors.New(fmt.Sprintf(pkg.OpenApiSpecNotFoundError, targetK8sVersion))
5050
}
5151
return nil, err

pkg/Errors.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package pkg
2+
3+
import (
4+
"errors"
5+
)
6+
7+
const OpenApiSpecNotFoundError = "openapi-spec not found for the k8s version %s"
8+
9+
var ErrOpenApiSpecNotFound = errors.New(OpenApiSpecNotFoundError)

pkg/K8sSchemaParser.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package pkg
2020
import (
2121
"bytes"
2222
"context"
23-
"errors"
2423
"fmt"
2524
"github.com/getkin/kin-openapi/openapi2"
2625
"github.com/getkin/kin-openapi/openapi2conv"
@@ -116,7 +115,7 @@ func (k *kubeCheckerImpl) downloadFile(releaseVersion string) ([]byte, error) {
116115
}
117116
defer resp.Body.Close()
118117
if resp.StatusCode == http.StatusNotFound {
119-
return []byte{}, errors.New(fmt.Sprintf(OpenApiSpecNotFoundError, releaseVersion))
118+
return []byte{}, ErrOpenApiSpecNotFound
120119
}
121120
var out bytes.Buffer
122121
_, err = io.Copy(&out, resp.Body)

pkg/Util.go

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030
const (
3131
gvFormat = "%s/%s"
3232
gvkFormat = "%s/%s/%s"
33-
34-
OpenApiSpecNotFoundError = "openapi-spec not found for the k8s version %s"
3533
)
3634

3735
func getKeyForGV(msg json.RawMessage) (string, error) {

0 commit comments

Comments
 (0)