-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3737 from afbjorklund/download
Add --download-only option to start command
- Loading branch information
Showing
8 changed files
with
180 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2016 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 machine | ||
|
||
import ( | ||
"crypto" | ||
"os" | ||
"path" | ||
|
||
"github.com/golang/glog" | ||
"github.com/jimmidyson/go-download" | ||
"github.com/pkg/errors" | ||
"golang.org/x/sync/errgroup" | ||
"k8s.io/minikube/pkg/minikube/assets" | ||
"k8s.io/minikube/pkg/minikube/bootstrapper" | ||
"k8s.io/minikube/pkg/minikube/console" | ||
"k8s.io/minikube/pkg/minikube/constants" | ||
) | ||
|
||
// CacheBinariesForBootstrapper will cache binaries for a bootstrapper | ||
func CacheBinariesForBootstrapper(version string, clusterBootstrapper string) error { | ||
binaries := bootstrapper.GetCachedBinaryList(clusterBootstrapper) | ||
|
||
var g errgroup.Group | ||
for _, bin := range binaries { | ||
bin := bin | ||
g.Go(func() error { | ||
if _, err := CacheBinary(bin, version); err != nil { | ||
return errors.Wrapf(err, "caching image %s", bin) | ||
} | ||
return nil | ||
}) | ||
} | ||
return g.Wait() | ||
} | ||
|
||
// CacheBinary will cache a binary on the host | ||
func CacheBinary(binary, version string) (string, error) { | ||
targetDir := constants.MakeMiniPath("cache", version) | ||
targetFilepath := path.Join(targetDir, binary) | ||
|
||
url := constants.GetKubernetesReleaseURL(binary, version) | ||
|
||
_, err := os.Stat(targetFilepath) | ||
// If it exists, do no verification and continue | ||
if err == nil { | ||
glog.Infof("Not caching binary, using %s", url) | ||
return targetFilepath, nil | ||
} | ||
if !os.IsNotExist(err) { | ||
return "", errors.Wrapf(err, "stat %s version %s at %s", binary, version, targetDir) | ||
} | ||
|
||
if err = os.MkdirAll(targetDir, 0777); err != nil { | ||
return "", errors.Wrapf(err, "mkdir %s", targetDir) | ||
} | ||
|
||
options := download.FileOptions{ | ||
Mkdirs: download.MkdirAll, | ||
} | ||
|
||
options.Checksum = constants.GetKubernetesReleaseURLSHA1(binary, version) | ||
options.ChecksumHash = crypto.SHA1 | ||
|
||
console.OutStyle("file-download", "Downloading %s %s", binary, version) | ||
if err := download.ToFile(url, targetFilepath, options); err != nil { | ||
return "", errors.Wrapf(err, "Error downloading %s %s", binary, version) | ||
} | ||
return targetFilepath, nil | ||
} | ||
|
||
// CopyBinary copies previously cached binaries into the path | ||
func CopyBinary(cr bootstrapper.CommandRunner, binary, path string) error { | ||
f, err := assets.NewFileAsset(path, "/usr/bin", binary, "0641") | ||
if err != nil { | ||
return errors.Wrap(err, "new file asset") | ||
} | ||
if err := cr.Copy(f); err != nil { | ||
return errors.Wrapf(err, "copy") | ||
} | ||
return nil | ||
} |