Skip to content
Closed
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
10 changes: 5 additions & 5 deletions cmd/ocm-backplane/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (
RunE: runLogin,
SilenceUsage: true,
}

errLoginConnection = errors.New("unable to connect to backplane api")
)

func init() {
Expand Down Expand Up @@ -208,9 +210,7 @@ func runLogin(cmd *cobra.Command, argv []string) (err error) {
// Hibernating, print an error
return fmt.Errorf("cluster %s is hibernating, login failed", clusterKey)
}
// Check API connection with configured proxy
err = bpConfig.CheckAPIConnection()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove bpConfig.CheckAPIConnection(), which is ping to api end-point and validates the connection?

connectionOk, err := config.testHttpRequestToBackplaneAPI()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tired changing the logic to only perform CheckAPIConnection only when the error returned is errLoginConnection but fails the test cases.

if errors.Is(err, errLoginConnection) {
			connectionErr := bpConfig.CheckAPIConnection()
			if connectionErr != nil {
				return fmt.Errorf("cannot connect to backplane API URL, check if you need to use a proxy/VPN to access backplane: %v", connectionErr)
			}
		}

Test result:

• Failure [1.378 seconds]
Login command
/Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:28
  check cluster login
  /Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:187
    should fail when BP API timeouts [It]
    /Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:294

    Expected
        <string>: can't login to cluster: unable to connect to backplane api: dial tcp i/o timeout
    to contain substring
        <string>: cannot connect to backplane API URL

while I was trying to tweak the test case, I think we can instead skip testing the api connectivity as the error message from doLogin has already did a "test" on the apiserver, we can expose the actual network error + a hint about proxy/vpn to make the error logic simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR fixed the error overwriting issue.

if err != nil {
if errors.Is(err, errLoginConnection) {
return fmt.Errorf("cannot connect to backplane API URL, check if you need to use a proxy/VPN to access backplane: %v", err)
}

Expand Down Expand Up @@ -354,8 +354,8 @@ func doLogin(api, clusterId, accessToken string) (string, error) {
if err != nil {
// trying to determine the error
errBody := err.Error()
if strings.Contains(errBody, "dial tcp") && strings.Contains(errBody, "i/o timeout") {
return "", fmt.Errorf("unable to connect to backplane api")
if strings.Contains(errBody, "dial tcp") || strings.Contains(errBody, "i/o timeout") {
return "", fmt.Errorf("%w: %w", errLoginConnection, err)
}

return "", err
Expand Down