Skip to content

Commit fc916f7

Browse files
authored
Merge pull request #2110 from r2d4/files-rootfs
~/.minikube/files as rootfs "layer"
2 parents 43e4b0c + 633fc4a commit fc916f7

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

pkg/minikube/assets/addons.go

+44-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"path/filepath"
2323
"strconv"
2424

25-
"github.com/golang/glog"
25+
"github.com/pkg/errors"
2626
"k8s.io/minikube/pkg/minikube/config"
2727
"k8s.io/minikube/pkg/minikube/constants"
2828
"k8s.io/minikube/pkg/util"
@@ -235,22 +235,53 @@ var Addons = map[string]*Addon{
235235
}, false, "registry-creds"),
236236
}
237237

238-
func AddMinikubeDirToAssets(minipath string, vmpath string, assetList *[]CopyableFile) {
239-
// loop over $MINIKUBE_HOME/minipath and add them to assets
240-
searchDir := constants.MakeMiniPath(minipath)
241-
err := filepath.Walk(searchDir, func(miniFile string, f os.FileInfo, err error) error {
242-
isDir, err := util.IsDirectory(miniFile)
243-
if err == nil && !isDir {
244-
f, err := NewFileAsset(miniFile, vmpath, filepath.Base(miniFile), "0640")
245-
if err == nil {
246-
*assetList = append(*assetList, f)
238+
func AddMinikubeDirAssets(assets *[]CopyableFile) error {
239+
if err := addMinikubeDirToAssets(constants.MakeMiniPath("addons"), constants.AddonsPath, assets); err != nil {
240+
return errors.Wrap(err, "adding addons folder to assets")
241+
}
242+
if err := addMinikubeDirToAssets(constants.MakeMiniPath("files"), "", assets); err != nil {
243+
return errors.Wrap(err, "adding files rootfs to assets")
244+
}
245+
246+
return nil
247+
}
248+
249+
// AddMinikubeDirToAssets adds all the files in the basedir argument to the list
250+
// of files to be copied to the vm. If vmpath is left blank, the files will be
251+
// transferred to the location according to their relative minikube folder path.
252+
func addMinikubeDirToAssets(basedir, vmpath string, assets *[]CopyableFile) error {
253+
err := filepath.Walk(basedir, func(hostpath string, info os.FileInfo, err error) error {
254+
isDir, err := util.IsDirectory(hostpath)
255+
if err != nil {
256+
return errors.Wrapf(err, "checking if %s is directory", hostpath)
257+
}
258+
if !isDir {
259+
if vmpath == "" {
260+
rPath, err := filepath.Rel(basedir, hostpath)
261+
if err != nil {
262+
return errors.Wrap(err, "generating relative path")
263+
}
264+
rPath = filepath.Dir(rPath)
265+
vmpath = filepath.Join("/", rPath)
266+
}
267+
permString := fmt.Sprintf("%o", info.Mode().Perm())
268+
// The conversion will strip the leading 0 if present, so add it back
269+
// if we need to.
270+
if len(permString) == 3 {
271+
permString = fmt.Sprintf("0%s", permString)
247272
}
248-
} else if err != nil {
249-
glog.Infoln(fmt.Sprintf("Error encountered while walking %s: ", searchDir), err)
273+
274+
f, err := NewFileAsset(hostpath, vmpath, filepath.Base(hostpath), permString)
275+
if err != nil {
276+
return errors.Wrapf(err, "creating file asset for %s", hostpath)
277+
}
278+
*assets = append(*assets, f)
250279
}
280+
251281
return nil
252282
})
253283
if err != nil {
254-
glog.Infoln(fmt.Sprintf("Error encountered while walking %s: ", searchDir), err)
284+
return errors.Wrap(err, "walking filepath")
255285
}
286+
return nil
256287
}

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ func (k *KubeadmBootstrapper) StartCluster(k8s bootstrapper.KubernetesConfig) er
132132
func addAddons(files *[]assets.CopyableFile) error {
133133
// add addons to file list
134134
// custom addons
135-
assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, files)
135+
if err := assets.AddMinikubeDirAssets(files); err != nil {
136+
return errors.Wrap(err, "adding minikube dir assets")
137+
}
136138
// bundled addons
137139
for addonName, addonBundle := range assets.Addons {
138140
// TODO(r2d4): Kubeadm ignores the kube-dns addon and uses its own.
@@ -259,15 +261,6 @@ func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) e
259261
assets.NewMemoryAssetTarget([]byte(kubeadmCfg), constants.KubeadmConfigFile, "0640"),
260262
}
261263

262-
if err := addAddons(&files); err != nil {
263-
return errors.Wrap(err, "adding addons to copyable files")
264-
}
265-
266-
for _, f := range files {
267-
if err := k.c.Copy(f); err != nil {
268-
return errors.Wrapf(err, "transferring kubeadm file: %+v", f)
269-
}
270-
}
271264
var g errgroup.Group
272265
for _, bin := range []string{"kubelet", "kubeadm"} {
273266
bin := bin
@@ -290,6 +283,16 @@ func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) e
290283
return errors.Wrap(err, "downloading binaries")
291284
}
292285

286+
if err := addAddons(&files); err != nil {
287+
return errors.Wrap(err, "adding addons to copyable files")
288+
}
289+
290+
for _, f := range files {
291+
if err := k.c.Copy(f); err != nil {
292+
return errors.Wrapf(err, "transferring kubeadm file: %+v", f)
293+
}
294+
}
295+
293296
err = k.c.Run(`
294297
sudo systemctl daemon-reload &&
295298
sudo systemctl enable kubelet &&

pkg/minikube/bootstrapper/localkube/localkube.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon
123123
}
124124
copyableFiles = append(copyableFiles, localkubeFile)
125125

126-
// user added files
127-
assets.AddMinikubeDirToAssets("files", constants.FilesPath, &copyableFiles)
128-
129126
// custom addons
130-
assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, &copyableFiles)
127+
if err := assets.AddMinikubeDirAssets(&copyableFiles); err != nil {
128+
return errors.Wrap(err, "adding minikube dir assets")
129+
}
131130
// bundled addons
132131
for _, addonBundle := range assets.Addons {
133132
if isEnabled, err := addonBundle.IsEnabled(); err == nil && isEnabled {

pkg/minikube/bootstrapper/ssh_runner.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
112112
}()
113113

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

0 commit comments

Comments
 (0)