Skip to content

Commit

Permalink
Merge pull request #2110 from r2d4/files-rootfs
Browse files Browse the repository at this point in the history
~/.minikube/files as rootfs "layer"
  • Loading branch information
r2d4 authored Nov 29, 2017
2 parents 43e4b0c + 633fc4a commit fc916f7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
57 changes: 44 additions & 13 deletions pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -235,22 +235,53 @@ 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)
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)
}
permString := fmt.Sprintf("%o", info.Mode().Perm())
// The conversion will strip the leading 0 if present, so add it back
// if we need to.
if len(permString) == 3 {
permString = fmt.Sprintf("0%s", permString)
}
} else if err != nil {
glog.Infoln(fmt.Sprintf("Error encountered while walking %s: ", searchDir), err)

f, err := NewFileAsset(hostpath, vmpath, filepath.Base(hostpath), permString)
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
}
23 changes: 13 additions & 10 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -259,15 +261,6 @@ func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) e
assets.NewMemoryAssetTarget([]byte(kubeadmCfg), constants.KubeadmConfigFile, "0640"),
}

if err := addAddons(&files); err != nil {
return errors.Wrap(err, "adding addons to copyable files")
}

for _, f := range files {
if err := k.c.Copy(f); err != nil {
return errors.Wrapf(err, "transferring kubeadm file: %+v", f)
}
}
var g errgroup.Group
for _, bin := range []string{"kubelet", "kubeadm"} {
bin := bin
Expand All @@ -290,6 +283,16 @@ func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) e
return errors.Wrap(err, "downloading binaries")
}

if err := addAddons(&files); err != nil {
return errors.Wrap(err, "adding addons to copyable files")
}

for _, f := range files {
if err := k.c.Copy(f); err != nil {
return errors.Wrapf(err, "transferring kubeadm file: %+v", f)
}
}

err = k.c.Run(`
sudo systemctl daemon-reload &&
sudo systemctl enable kubelet &&
Expand Down
7 changes: 3 additions & 4 deletions pkg/minikube/bootstrapper/localkube/localkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/minikube/bootstrapper/ssh_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
}()

scpcmd := fmt.Sprintf("sudo scp -t %s", f.GetTargetDir())
if err := sess.Run(scpcmd); err != nil {
return errors.Wrapf(err, "Error running scp command: %s", scpcmd)
out, err := sess.CombinedOutput(scpcmd)
if err != nil {
return errors.Wrapf(err, "Error running scp command: %s output: %s", scpcmd, out)
}
wg.Wait()

Expand Down

0 comments on commit fc916f7

Please sign in to comment.