commit
fc916f7af1
|
@ -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"
|
||||
|
@ -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)
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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 &&
|
||||
|
|
|
@ -123,11 +123,10 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon
|
|||
}
|
||||
copyableFiles = append(copyableFiles, localkubeFile)
|
||||
|
||||
// user added files
|
||||
assets.AddMinikubeDirToAssets("files", constants.FilesPath, ©ableFiles)
|
||||
|
||||
// custom addons
|
||||
assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, ©ableFiles)
|
||||
if err := assets.AddMinikubeDirAssets(©ableFiles); 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 {
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue