Skip to content

Commit

Permalink
Add Unclassified error type (#20)
Browse files Browse the repository at this point in the history
* Add Unclassified error type

* Update volume interface package

* Fix error messages
  • Loading branch information
prankulmahajan authored Sep 30, 2021
1 parent 0473b5b commit aed3721
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
11 changes: 9 additions & 2 deletions common/iam/token_exchange_iks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest"
Expand Down Expand Up @@ -151,10 +152,16 @@ func (r *tokenExchangeIKSRequest) sendTokenExchangeRequest() (*tokenExchangeIKSR
r.logger.Info("Sending IAM token exchange request to container api server")
resp, err := r.client.Do(r.request, &successV, &errorV)
if err != nil {
errString := err.Error()
r.logger.Error("IAM token exchange request failed", zap.Reflect("Response", resp), zap.Error(err))
return nil,
util.NewError("ErrorUnclassified",
if strings.Contains(errString, "no such host") {
return nil, util.NewError("EndpointNotReachable", errString)
} else if strings.Contains(errString, "Timeout") {
return nil, util.NewError("Timeout", errString)
} else {
return nil, util.NewError("ErrorUnclassified",
"IAM token exchange request failed", err)
}
}

if resp != nil && resp.StatusCode == 200 {
Expand Down
11 changes: 11 additions & 0 deletions common/messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

util "github.com/IBM/ibmcloud-volume-interface/lib/utils"
"github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode"
)

// MessagesEn ...
Expand Down Expand Up @@ -55,3 +56,13 @@ func GetUserError(code string, err error, args ...interface{}) error {
}
return userMsg
}

// GetUserErrorCode returns reason code string if a util.Message, else ErrorUnclassified string
func GetUserErrorCode(err error) string {
if uErr, isPerr := err.(util.Message); isPerr {
if code := uErr.Code; code != "" {
return code
}
}
return string(reasoncode.ErrorUnclassified)
}
14 changes: 14 additions & 0 deletions common/messages/messages_en.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ var messagesEn = map[string]util.Message{
RC: 400,
Action: "Verify that you entered the correct IBM Cloud user name and password. If the error persists, the authentication service might be unavailable. Wait a few minutes and try again. ",
},
"EndpointNotReachable": {
Code: "EndpointNotReachable",
Description: "IAM TOKEN exchange request failed.",
Type: util.FailedAccessToken,
RC: 500,
Action: "Verify that iks_token_exchange_endpoint_private_url is reachable from the cluster. You can find this url by running 'kubectl get secret storage-secret-storage -n kube-system'.",
},
"Timeout": {
Code: "Timeout",
Description: "IAM Token exchange endpoint is not reachable.",
Type: util.FailedAccessToken,
RC: 503,
Action: "Wait for a few mninutes and try again. If the error persists user can open a container network issue.",
},
"ErrorRequiredFieldMissing": {
Code: "ErrorRequiredFieldMissing",
Description: "[%s] is required to complete the operation.",
Expand Down
4 changes: 4 additions & 0 deletions common/messages/reason_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
package messages

const (
//Timeout indicates IAM_TOKEN exchange request failed due to timeout
Timeout = "Timeout"
//EndpointNotReachable indicates IAM_TOKEN exchange request failed due to incorrect endpoint
EndpointNotReachable = "EndpointNotReachable"
//AuthenticationFailed indicate authentication to IAM endpoint failed. e,g IAM_TOKEN refresh
AuthenticationFailed = "AuthenticationFailed"
//VolumeAttachFailed indicates if volume attach to instance is failed
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ go 1.15

require (
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta7
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta8
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fatih/structs v1.1.0
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0 // indirect
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.15.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7 h1:eHgfQl6IeSmzWUyiSi13CvoFYsovoyqWlpHX0pa9J54=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta7 h1:cl1situtbkJwEsRDw1CW2KpJkmznmjzhWWnSPH3TzvM=
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta7/go.mod h1:2LxqkERml3eBxfRkQniuiRmKkAnl5tfC0ttlP2gupJM=
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta8 h1:0oCBQidejAlLI5f5PlBHIytArhJI1aEOBCCOMoxNOPs=
github.com/IBM/ibmcloud-volume-interface v1.0.0-beta8/go.mod h1:2LxqkERml3eBxfRkQniuiRmKkAnl5tfC0ttlP2gupJM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -63,8 +63,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0 h1:i5VIxp6QB8oWZ8IkK8zrDgeT6ORGIUeiN+61iETwJbI=
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0/go.mod h1:4xpMLz7RBWyB+ElzHu8Llua96TRCB3YwX+l5EP1wmHk=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
13 changes: 11 additions & 2 deletions iks/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"

"github.com/IBM/ibmcloud-volume-interface/lib/provider"
util "github.com/IBM/ibmcloud-volume-interface/lib/utils"
utilReasonCode "github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode"
"github.com/IBM/ibmcloud-volume-interface/provider/local"
vpcprovider "github.com/IBM/ibmcloud-volume-vpc/block/provider"
vpcconfig "github.com/IBM/ibmcloud-volume-vpc/block/vpcconfig"
Expand Down Expand Up @@ -75,8 +77,15 @@ func (iksp *IksVpcBlockProvider) OpenSession(ctx context.Context, contextCredent
vpcContextCredentials, err := ccf.ForIAMAccessToken(iksp.iksBlockProvider.Config.VPCConfig.APIKey, ctxLogger)
if err != nil {
ctxLogger.Error("Error occurred while generating IAM token for VPC", zap.Error(err))
userErr := userError.GetUserError(string(userError.AuthenticationFailed), err)
return nil, userErr
if util.ErrorReasonCode(err) == utilReasonCode.EndpointNotReachable {
userErr := userError.GetUserError(string(userError.EndpointNotReachable), err)
return nil, userErr
}
if util.ErrorReasonCode(err) == utilReasonCode.Timeout {
userErr := userError.GetUserError(string(userError.Timeout), err)
return nil, userErr
}
return nil, err
}
session, err := iksp.vpcBlockProvider.OpenSession(ctx, vpcContextCredentials, ctxLogger)
if err != nil {
Expand Down

0 comments on commit aed3721

Please sign in to comment.