Unverified Commit 131eb2a8 authored by Med G's avatar Med G

exit with usage when need login to github

parent 07c7b7ca
......@@ -34,7 +34,7 @@ const (
var (
// BaseImage is the base image is used to spin up kic containers. it uses same base-image as kind.
BaseImage = fmt.Sprintf("gcr.io/k8s-minikube/kicbase:%[email protected]:%s", Version, baseImageSHA)
BaseImage = fmt.Sprintf("gcr.io/k8s-minikube/kicbase1:%[email protected]:%s", Version, baseImageSHA)
// BaseImageFallBack the fall back of BaseImage in case gcr.io is not available. stored in github packages https://github.com/kubernetes/minikube/packages/206071
// github packages docker does _NOT_ support pulling by sha as mentioned in the docs:
// https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages
......
......@@ -18,6 +18,7 @@ package image
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
......@@ -103,6 +104,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])
......@@ -120,11 +129,13 @@ func WriteImageToDaemon(img string) error {
//
// https://github.com/google/go-containerregistry/pull/702
fmt.Println("---------------pulling image----------------")
glog.V(3).Infof("Pulling image %v", ref)
// Pull digest
cmd := exec.Command("docker", "pull", "--quiet", img)
if _, err := cmd.Output(); err != nil {
fmt.Printf("---------------ERROR pulling image----------------: %v", err)
return errors.Wrap(err, "pulling remote image")
}
......
/*
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 regsitery needs login (a general)
var ErrNeedsLogin error
// ErrGithubNeedsLogin is thrown when user needs to login to github to use the fall back image
var ErrGithubNeedsLogin error
......@@ -19,6 +19,7 @@ package node
import (
"os"
"runtime"
"strings"
"github.com/golang/glog"
"github.com/pkg/errors"
......@@ -126,8 +127,21 @@ 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.T(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 into to the github packages registry")
out.T(out.Documentation, "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 the registry or use --base-image option to use a different registry.`)
} else {
glog.Errorln("Error downloading kic artifacts: ", err)
}
}
}
glog.Info("Successfully downloaded all kic artifacts")
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment