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

~/.minikube/files as rootfs "layer" #2110

Merged
merged 4 commits into from
Nov 29, 2017
Merged
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
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 @@ -196,22 +196,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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this will work with Windows as you stated. Should be able to massage the paths though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the tests will cover this, I don't think any integration tests use the .minikube/files dir.

vmpath = filepath.Join("/", rPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think this one needs to be a path.Join

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well the tricky thing is that I'm using the host path to determine the remote path.

so rPath is always the relative path to your MINIKUBE_HOME.

Essentially it boils down to - how to do you translate a unix path from a partial windows path? I don't think we can just reverse the slashes and call it day.

}
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