Skip to content

Commit

Permalink
Merge pull request #8225 from medyagh/gh_package_login
Browse files Browse the repository at this point in the history
exit with usage when need login to image registry
  • Loading branch information
medyagh authored May 21, 2020
2 parents 70e5d3c + 2c0719e commit 25045cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/minikube/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
23 changes: 23 additions & 0 deletions pkg/minikube/image/types.go
Original file line number Diff line number Diff line change
@@ -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
20 changes: 18 additions & 2 deletions pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package node
import (
"os"
"runtime"
"strings"

"github.com/golang/glog"
"github.com/pkg/errors"
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 25045cf

Please sign in to comment.