Add informative error messages when there is no internet connection. (#11377)

When the Linkerd CLI is unable to access the internet, it will encounter
a DNS error when trying to discover the latest Linkerd releases from linkerd.io.

This change handles this DNS resolution error explicitly so that users receive
a more informative error message.

Fixes #11349

Signed-off-by: Dominik Táskai <dominik.taskai@leannet.eu>
Co-authored-by: Dominik Táskai <dominik.taskai@leannet.eu>
Co-authored-by: Oliver Gould <ver@buoyant.io>
This commit is contained in:
Táskai Dominik 2023-09-26 19:23:56 +02:00 committed by GitHub
parent 74337f9d25
commit 64b66f9218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -1439,6 +1439,9 @@ func CheckProxyVersionsUpToDate(pods []corev1.Pod, versions version.Channels) er
}
}
}
if versions.Empty() {
return errors.New("unable to determine version channel")
}
if len(outdatedPods) > 0 {
podList := strings.Join(outdatedPods, "\n")
return fmt.Errorf("some proxies are not running the current version:\n%s", podList)

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"github.com/linkerd/linkerd2/pkg/util"
@ -44,6 +45,10 @@ func (c Channels) Match(actualVersion string) error {
return errors.New("actual version is empty")
}
if c.Empty() {
return errors.New("unable to determine version channel")
}
actual, err := parseChannelVersion(actualVersion)
if err != nil {
return fmt.Errorf("failed to parse actual version: %w", err)
@ -58,6 +63,11 @@ func (c Channels) Match(actualVersion string) error {
return fmt.Errorf("unsupported version channel: %s", actualVersion)
}
// Determines whether there are any release channels stored in the struct.
func (c Channels) Empty() bool {
return len(c.array) == 0
}
// GetLatestVersions performs an online request to check for the latest Linkerd
// release channels.
func GetLatestVersions(ctx context.Context, uuid string, source string) (Channels, error) {
@ -73,6 +83,10 @@ func getLatestVersions(ctx context.Context, client *http.Client, url string) (Ch
rsp, err := client.Do(req.WithContext(ctx))
if err != nil {
var dnsError *net.DNSError
if errors.As(err, &dnsError) {
return Channels{}, fmt.Errorf("failed to resolve version check server: %s", url)
}
return Channels{}, err
}
defer rsp.Body.Close()