diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 05904d9e93a2..7c68a8c58828 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -103,6 +103,14 @@ func WriteImageToDaemon(img string) error { glog.V(3).Infof("Getting image %v", ref) i, err := remote.Image(ref) if err != nil { + if strings.Contains(err.Error(), "GitHub Docker Registry needs login") { + ErrGithubNeedsLogin = errors.New(err.Error()) + return ErrGithubNeedsLogin + } else if strings.Contains(err.Error(), "UNAUTHORIZED") { + ErrNeedsLogin = errors.New(err.Error()) + return ErrNeedsLogin + } + return errors.Wrap(err, "getting remote image") } tag, err := name.NewTag(strings.Split(img, "@")[0]) diff --git a/pkg/minikube/image/types.go b/pkg/minikube/image/types.go new file mode 100644 index 000000000000..ed396358ac79 --- /dev/null +++ b/pkg/minikube/image/types.go @@ -0,0 +1,23 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package image + +// ErrNeedsLogin is thrown when registry needs login (a general error) +var ErrNeedsLogin error + +// ErrGithubNeedsLogin is thrown when user needs to login specifically to github packages) +var ErrGithubNeedsLogin error diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index d5a36a5e15db..2de6f6a130b8 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -19,6 +19,7 @@ package node import ( "os" "runtime" + "strings" "github.com/golang/glog" "github.com/pkg/errors" @@ -126,8 +127,23 @@ func beginDownloadKicArtifacts(g *errgroup.Group, cc *config.ClusterConfig) { // WaitDownloadKicArtifacts blocks until the required artifacts for KIC are downloaded. func waitDownloadKicArtifacts(g *errgroup.Group) { if err := g.Wait(); err != nil { - glog.Errorln("Error downloading kic artifacts: ", err) - return + if err != nil { + if errors.Is(err, image.ErrGithubNeedsLogin) { + glog.Warningf("Error downloading kic artifacts: %v", err) + out.ErrT(out.Connectivity, "Unfortunately, could not download the base image {{.image_name}} ", out.V{"image_name": strings.Split(kic.BaseImage, "@")[0]}) + out.WarningT("In order to use the fall back image, you need to log in to the github packages registry") + out.T(out.Documentation, `Please visit the following link for documentation around this: + https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages +`) + } + if errors.Is(err, image.ErrGithubNeedsLogin) || errors.Is(err, image.ErrNeedsLogin) { + exit.UsageT(`Please either authenticate to the registry or use --base-image flag to use a different registry.`) + } else { + glog.Errorln("Error downloading kic artifacts: ", err) + } + + } + } glog.Info("Successfully downloaded all kic artifacts") }