提交 a03c239c 编写于 作者: P Priya Wadhwa

Add k8s binaries to preloaded tarball

Include k8s binaries in preloaded tarball so that we can skip tranferring this over.

This increases the size of the tarball from around 430 MB to 500MB, but saves a couple seconds on start time.
上级 22ca04aa
......@@ -27,7 +27,10 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/drivers/kic"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/localpath"
)
......@@ -110,6 +113,14 @@ func executePreloadImages() error {
}
}
// Transfer in k8s binaries
kcfg := config.KubernetesConfig{
KubernetesVersion: kubernetesVersion,
}
runner := command.NewKICRunner(profile, driver.OCIBinary)
if err := bsutil.TransferBinaries(kcfg, runner); err != nil {
return errors.Wrap(err, "transferring k8s binaries")
}
// Create image tarball
if err := createImageTarball(); err != nil {
return err
......@@ -121,6 +132,7 @@ func createImageTarball() error {
dirs := []string{
fmt.Sprintf("./lib/docker/%s", dockerStorageDriver),
"./lib/docker/image",
"./lib/minikube/binaries",
}
args := []string{"exec", profile, "sudo", "tar", "-I", "lz4", "-C", "/var", "-cvf", tarballFilename}
args = append(args, dirs...)
......
......@@ -18,10 +18,13 @@ limitations under the License.
package bsutil
import (
"fmt"
"os/exec"
"path"
"runtime"
"strings"
"github.com/golang/glog"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"k8s.io/minikube/pkg/minikube/command"
......@@ -33,8 +36,15 @@ import (
// TransferBinaries transfers all required Kubernetes binaries
func TransferBinaries(cfg config.KubernetesConfig, c command.Runner) error {
ok, err := binariesExist(cfg, c)
if err == nil && ok {
glog.Info("Found k8s binaries, skipping transfer")
return nil
}
glog.Infof("Didn't find k8s binaries: %v\nInitiating transfer...", err)
dir := binRoot(cfg.KubernetesVersion)
_, err := c.RunCmd(exec.Command("sudo", "mkdir", "-p", dir))
_, err = c.RunCmd(exec.Command("sudo", "mkdir", "-p", dir))
if err != nil {
return err
}
......@@ -58,6 +68,26 @@ func TransferBinaries(cfg config.KubernetesConfig, c command.Runner) error {
return g.Wait()
}
// binariesExist returns true if the binaries already exist
func binariesExist(cfg config.KubernetesConfig, c command.Runner) (bool, error) {
dir := binRoot(cfg.KubernetesVersion)
rr, err := c.RunCmd(exec.Command("sudo", "ls", dir))
stdout := rr.Stdout.String()
if err != nil {
return false, err
}
foundBinaries := map[string]struct{}{}
for _, binary := range strings.Split(stdout, "\n") {
foundBinaries[binary] = struct{}{}
}
for _, name := range constants.KubernetesReleaseBinaries {
if _, ok := foundBinaries[name]; !ok {
return false, fmt.Errorf("didn't find preexisting %s", name)
}
}
return true, nil
}
// binRoot returns the persistent path binaries are stored in
func binRoot(version string) string {
return path.Join(vmpath.GuestPersistentDir, "binaries", version)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册