Skip to content
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

feat: allow publish and download kicbase image in github release #19464

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion hack/jenkins/release_build_and_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ grep -E "^VERSION_BUILD \\?=" Makefile | grep "${VERSION_BUILD}"

# Force go packages to the Jekins home directory
export GOPATH=$HOME/go

# Make sure docker is installed and configured
./hack/jenkins/installers/check_install_docker.sh
# Verify ISO exists
echo "Verifying ISO exists ..."
make verify-iso
Expand Down Expand Up @@ -111,5 +112,20 @@ fi
#echo "Updating Docker images ..."
#make push-gvisor-addon-image push-storage-provisioner-manifest

echo "Generating tarballs for kicbase images"
# first get the correct tag of the kic base image
KIC_VERSION=$(grep -E "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 1)
# then generate tarballs for all achitectures
for ARCH in "amd64" "arm64" "arm/v7" "ppc64le" "s390x"
do
SUFFIX=$(echo $ARCH | sed 's/\///g')
IMAGE_NAME=kicbase/stable:${KIC_VERSION}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we ensure that this image is already pushed into the registry ...otherwise it wont find it...(maybe it is somewhere up in the script that pushes the image)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spowelljr is this the correct place to generate the tarball for new kicbase image? I guess this is a part of jenkins job, and the docker image should have been pushed into registry before this?

TARBALL_NAME=out/kicbase-${KIC_VERSION}-${SUFFIX}.tar
docker pull ${IMAGE_NAME} --platform linux/${ARCH}
docker image save ${IMAGE_NAME} -o ${TARBALL_NAME}
openssl sha256 "${TARBALL_NAME}" | awk '{print $2}' > "${TARBALL_NAME}.sha256"
docker rmi -f ${IMAGE_NAME}
done

echo "Updating latest bucket for ${VERSION} release ..."
gsutil cp -r "gs://${BUCKET}/releases/${TAGNAME}/*" "gs://${BUCKET}/releases/latest/"
3 changes: 2 additions & 1 deletion pkg/minikube/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CreateDstDownloadMock(_, dst string) error {
}

// download is a well-configured atomic download function
func download(src, dst string) error {
func download(src, dst string, options ...getter.ClientOption) error {
var clientOptions []getter.ClientOption
if out.IsTerminal(os.Stdout) && !detect.GithubActionRunner() {
progress := getter.WithProgress(DefaultProgressBar)
Expand All @@ -76,6 +76,7 @@ func download(src, dst string) error {
} else {
clientOptions = []getter.ClientOption{}
}
clientOptions = append(clientOptions, options...)
tmpDst := dst + ".download"
client := &getter.Client{
Src: src,
Expand Down
33 changes: 33 additions & 0 deletions pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ import (
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
"k8s.io/minikube/pkg/version"
)

var (
Expand Down Expand Up @@ -224,6 +226,37 @@ func ImageToCache(img string) error {
}
}

// GHImageTarballToCache try to download the tarball of kicbase from github release.
// This is the last resort, in case of all docker registry is not available.
func GHImageTarballToCache(img, imgVersion string) (string, error) {
f := imagePathInCache(img)
fileLock := f + ".lock"

kicbaseArch := runtime.GOARCH
if kicbaseArch == "arm" {
kicbaseArch = "armv7"
}

releaser, err := lockDownload(fileLock)
if err != nil {
return "", err
}
if releaser != nil {
defer releaser.Release()
}
downloadURL := fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/%s/%s-%s-%s.tar",
version.GetVersion(),
img, imgVersion, kicbaseArch)

// we don't want the tarball to be decompressed
// so we pass client options to suppress this behavior
if err := download(downloadURL, f, getter.WithDecompressors(map[string]getter.Decompressor{})); err != nil {
return "", err
}
return downloadURL, nil

}

func parseImage(img string) (*name.Tag, name.Reference, error) {

var ref name.Reference
Expand Down
39 changes: 36 additions & 3 deletions pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
if finalImg != "" {
cc.KicBaseImage = finalImg
if image.Tag(finalImg) != image.Tag(baseImg) {
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), image.Tag(finalImg)))
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), finalImg))
}
}
}()
// first we try to download the kicbase image (and fall back images) from docker registry
var err error
for _, img := range append([]string{baseImg}, kic.FallbackImages...) {
var err error

if driver.IsDocker(cc.Driver) && download.ImageExistsInDaemon(img) && !downloadOnly {
klog.Infof("%s exists in daemon, skipping load", img)
Expand Down Expand Up @@ -167,7 +168,39 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
}
klog.Infof("failed to download %s, will try fallback image if available: %v", img, err)
}
return fmt.Errorf("failed to download kic base image or any fallback image")
// second if we failed to download any fallback image
// that means probably all registries are blocked by network issues
// we can try to download the image from minikube release page

// if we reach here, that means the user cannot have access to any docker registry
// this means the user is very likely to have a network issue
// downloading from github via http is the last resort, and we should remind the user
// that he should at least get access to github
// print essential warnings
out.WarningT("minikube cannot pull kicbase image from any docker registry, and is trying to download kicbase tarball from github release page via HTTP.")
out.WarningT("It's very likely that you have an internet issue. Please ensure that you can access the internet at least via HTTP, directly or with proxy. Currently your proxy configure is:")
envs := []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy", "ALL_PROXY", "NO_PROXY"}
for _, env := range envs {
if v := os.Getenv(env); v != "" {
out.Infof("{{.env}}={{.value}}", out.V{"env": env, "value": v})
}
}
out.Ln("")

kicbaseVersion := strings.Split(kic.Version, "-")[0]
finalImg, err = download.GHImageTarballToCache("kicbase", kicbaseVersion)
if err != nil {
klog.Infof("failed to download %s", finalImg)
return fmt.Errorf("failed to download kic base image or any fallback image")
}
klog.Infof("successfully downloaded %s as fall back image", finalImg)
if !downloadOnly && driver.IsDocker(cc.Driver) {
if finalImg, err = download.CacheToDaemon("kicbase"); err == nil {
klog.Infof("successfully loaded and using kicbase from tarball on github")
}
}
return nil

})
}

Expand Down
Loading