Apply MINIKUBE_HOME/files as "rootfs" layer

Instead of scping these files to just /files, we mimic the directory
structure relative to the ~/.minikube/files directory and place the
binaries there.  This can be useful for development.
pull/2110/head
Matt Rickard 2017-10-23 15:03:28 -07:00
parent ea31492976
commit fc84bfde0b
3 changed files with 46 additions and 19 deletions

View File

@ -22,7 +22,7 @@ import (
"path/filepath"
"strconv"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/util"
@ -196,22 +196,48 @@ var Addons = map[string]*Addon{
}, false, "registry-creds"),
}
func AddMinikubeDirToAssets(minipath string, vmpath string, assetList *[]CopyableFile) {
// loop over $MINIKUBE_HOME/minipath and add them to assets
searchDir := constants.MakeMiniPath(minipath)
err := filepath.Walk(searchDir, func(miniFile string, f os.FileInfo, err error) error {
isDir, err := util.IsDirectory(miniFile)
if err == nil && !isDir {
f, err := NewFileAsset(miniFile, vmpath, filepath.Base(miniFile), "0640")
if err == nil {
*assetList = append(*assetList, f)
}
} else if err != nil {
glog.Infoln(fmt.Sprintf("Error encountered while walking %s: ", searchDir), err)
func AddMinikubeDirAssets(assets *[]CopyableFile) error {
if err := addMinikubeDirToAssets(constants.MakeMiniPath("addons"), constants.AddonsPath, assets); err != nil {
return errors.Wrap(err, "adding addons folder to assets")
}
if err := addMinikubeDirToAssets(constants.MakeMiniPath("files"), "", assets); err != nil {
return errors.Wrap(err, "adding files rootfs to assets")
}
return nil
}
// AddMinikubeDirToAssets adds all the files in the basedir argument to the list
// of files to be copied to the vm. If vmpath is left blank, the files will be
// transferred to the location according to their relative minikube folder path.
func addMinikubeDirToAssets(basedir, vmpath string, assets *[]CopyableFile) error {
err := filepath.Walk(basedir, func(hostpath string, info os.FileInfo, err error) error {
isDir, err := util.IsDirectory(hostpath)
if err != nil {
return errors.Wrapf(err, "checking if %s is directory", hostpath)
}
if !isDir {
if vmpath == "" {
rPath, err := filepath.Rel(basedir, hostpath)
if err != nil {
return errors.Wrap(err, "generating relative path")
}
rPath = filepath.Dir(rPath)
vmpath = filepath.Join("/", rPath)
}
// While not technically correct, we add a leading 0 here (this won't account for the higher order permissions)
// Since the leading 0 is stripped when converting to octal.
f, err := NewFileAsset(hostpath, vmpath, filepath.Base(hostpath), fmt.Sprintf("0%o", info.Mode().Perm()))
if err != nil {
return errors.Wrapf(err, "creating file asset for %s", hostpath)
}
*assets = append(*assets, f)
}
return nil
})
if err != nil {
glog.Infoln(fmt.Sprintf("Error encountered while walking %s: ", searchDir), err)
return errors.Wrap(err, "walking filepath")
}
return nil
}

View File

@ -132,7 +132,9 @@ func (k *KubeadmBootstrapper) StartCluster(k8s bootstrapper.KubernetesConfig) er
func addAddons(files *[]assets.CopyableFile) error {
// add addons to file list
// custom addons
assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, files)
if err := assets.AddMinikubeDirAssets(files); err != nil {
return errors.Wrap(err, "adding minikube dir assets")
}
// bundled addons
for addonName, addonBundle := range assets.Addons {
// TODO(r2d4): Kubeadm ignores the kube-dns addon and uses its own.

View File

@ -123,11 +123,10 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon
}
copyableFiles = append(copyableFiles, localkubeFile)
// user added files
assets.AddMinikubeDirToAssets("files", constants.FilesPath, &copyableFiles)
// custom addons
assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, &copyableFiles)
if err := assets.AddMinikubeDirAssets(&copyableFiles); err != nil {
return errors.Wrap(err, "adding minikube dir assets")
}
// bundled addons
for _, addonBundle := range assets.Addons {
if isEnabled, err := addonBundle.IsEnabled(); err == nil && isEnabled {