Skip to content

suggest using default cluster port on internal server error #12654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
16 changes: 10 additions & 6 deletions pkg/cmd/cli/cmd/login/loginoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"

Expand Down Expand Up @@ -138,12 +139,8 @@ func (o *LoginOptions) getClientConfig() (*restclient.Config, error) {
case tls.RecordHeaderError:
return nil, clientcmd.GetPrettyErrorForServer(err, o.Server)
default:
// suggest the port used in the cluster URL by default, in case we're not already using it
host, port, parsed, err1 := getHostPort(o.Server)
_, defaultClusterPort, _, err2 := getHostPort(defaultClusterURL)
if err1 == nil && err2 == nil && port != defaultClusterPort {
parsed.Host = net.JoinHostPort(host, defaultClusterPort)
return nil, fmt.Errorf("%s\nYou may want to try using the default cluster port: %s", err.Error(), parsed.String())
if _, ok := err.(*net.OpError); ok {
return nil, fmt.Errorf("%v - verify you have provided the correct host and port and that the server is currently running.", err)
}
return nil, err
}
Expand Down Expand Up @@ -228,6 +225,13 @@ func (o *LoginOptions) gatherAuthInfo() error {
clientConfig.KeyFile = o.KeyFile
token, err := tokencmd.RequestToken(o.Config, o.Reader, o.Username, o.Password)
if err != nil {
// if internal error occurs, suggest making sure
// client is connecting to the right host:port
if statusErr, ok := err.(*kerrors.StatusError); ok {
if statusErr.Status().Code == http.StatusInternalServerError {
return fmt.Errorf("error: The server was unable to respond - verify you have provided the correct host and port and that the server is currently running.")
}
}
return err
}
clientConfig.BearerToken = token
Expand Down