@@ -22,7 +22,7 @@ import (
22
22
"path/filepath"
23
23
"strconv"
24
24
25
- "github.com/golang/glog "
25
+ "github.com/pkg/errors "
26
26
"k8s.io/minikube/pkg/minikube/config"
27
27
"k8s.io/minikube/pkg/minikube/constants"
28
28
"k8s.io/minikube/pkg/util"
@@ -235,22 +235,53 @@ var Addons = map[string]*Addon{
235
235
}, false , "registry-creds" ),
236
236
}
237
237
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 )
247
272
}
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 )
250
279
}
280
+
251
281
return nil
252
282
})
253
283
if err != nil {
254
- glog . Infoln ( fmt . Sprintf ( "Error encountered while walking %s: " , searchDir ), err )
284
+ return errors . Wrap ( err , " walking filepath" )
255
285
}
286
+ return nil
256
287
}
0 commit comments