Repository: threefoldtech/zos
Pull request #375 (2019-11-08 13:49:07)

Master flister mount options

codecov[bot]: # [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=h1) Report
> Merging [#375](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=desc) into [master](https://codecov.io/gh/threefoldtech/zos/commit/d370e9f7595850d5ef9d9cfa8769b2a33788c0ec?src=pr&el=desc) will **increase** coverage by `0.08%`.
> The diff coverage is `64.28%`.

[![Impacted file tree graph](https://codecov.io/gh/threefoldtech/zos/pull/375/graphs/tree.svg?width=650&token=f7Vmq1OAEm&height=150&src=pr)](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #375      +/-   ##
==========================================
+ Coverage   40.94%   41.02%   +0.08%     
==========================================
  Files          62       62              
  Lines        3842     3829      -13     
==========================================
- Hits         1573     1571       -2     
+ Misses       2058     2048      -10     
+ Partials      211      210       -1
```


| [Impacted Files](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/upgrade/upgrade.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL3VwZ3JhZGUvdXBncmFkZS5nbw==) | `0% <0%> (ø)` | :arrow_up: |
| [pkg/provision/zdb.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL3Byb3Zpc2lvbi96ZGIuZ28=) | `35.71% <100%> (ø)` | :arrow_up: |
| [pkg/provision/container.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL3Byb3Zpc2lvbi9jb250YWluZXIuZ28=) | `53.9% <100%> (ø)` | :arrow_up: |
| [pkg/flist/flist.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL2ZsaXN0L2ZsaXN0Lmdv) | `55.49% <63.63%> (+0.12%)` | :arrow_up: |
| [pkg/schema/types.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL3NjaGVtYS90eXBlcy5nbw==) | `56.12% <0%> (-2.88%)` | :arrow_down: |
| [pkg/identity/identityd.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL2lkZW50aXR5L2lkZW50aXR5ZC5nbw==) | `0% <0%> (ø)` | :arrow_up: |
| [pkg/identity/store.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL2lkZW50aXR5L3N0b3JlLmdv) | `0% <0%> (ø)` | :arrow_up: |
| [pkg/gedis/commands\_identity.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL2dlZGlzL2NvbW1hbmRzX2lkZW50aXR5Lmdv) | `64.12% <0%> (+0.68%)` | :arrow_up: |
| [pkg/environment/environment.go](https://codecov.io/gh/threefoldtech/zos/pull/375/diff?src=pr&el=tree#diff-cGtnL2Vudmlyb25tZW50L2Vudmlyb25tZW50Lmdv) | `71.42% <0%> (+4.76%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=footer). Last update [d370e9f...47b6a22](https://codecov.io/gh/threefoldtech/zos/pull/375?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs/migration/readme.md b/docs/migration/readme.md
new file mode 100644
index 00000000..678c463f
--- /dev/null
+++ b/docs/migration/readme.md
@@ -0,0 +1,8 @@
+# Migration to latest V2 version
+
+## From V1
+Unfortunately V2 is not compatible with V1 because the entire reservation process has been updated, hence there is noway to be backward compatible.
+
+To migrate to V2, you need to simply build a boot image as per the [bootstrap](https://bootstrap.grid.tf) then boot your node with this new image.
+
+Because there is no compatiblity wih V1, ZOS V2 will reuse the disks and apply the new disk layout which means **<span style="color: red">ALL THE DATA ON THE NODE WILL BE DELETED</span>**
\ No newline at end of file
diff --git a/docs/readme.md b/docs/readme.md
index 7f98dd8b..c817a8c6 100644
--- a/docs/readme.md
+++ b/docs/readme.md
@@ -4,6 +4,7 @@
 
 - Documentation about version:
   - [Release workflow](release/readme.md)
+  - [Migration to V2](migration/readme.md)
 
 - Documentation for each modules:
   - [Container](container/readme.md)
diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go
index 0313e212..a10f4dce 100644
--- a/pkg/environment/environment.go
+++ b/pkg/environment/environment.go
@@ -57,9 +57,10 @@ var (
 		// ProvisionInterval: 10,
 	}
 
+	// same as testnet for now. will be updated the day of the launch of production network
 	envProd = Environment{
 		RunningMode:   RunningMain,
-		BcdbURL:       "tcp://172.17.0.2:8901", //TODO: change once BCDB is online
+		BcdbURL:       "tcp://explorer.testnet.grid.tf:8901",
 		BcdbNamespace: "default",
 		// ProvisionTimeout:  240,
 		// ProvisionInterval: 20,
diff --git a/pkg/flist.go b/pkg/flist.go
index bd7278f8..e1b0abca 100644
--- a/pkg/flist.go
+++ b/pkg/flist.go
@@ -4,11 +4,34 @@ package pkg
 
 //go:generate zbusc -module flist -version 0.0.1 -name flist -package stubs github.com/threefoldtech/zos/pkg+Flister stubs/flist_stub.go
 
+var (
+	//DefaultMountOptions has sane values for mount
+	DefaultMountOptions = MountOptions{
+		ReadOnly: false,
+		Limit:    256, //Mib
+	}
+
+	//ReadOnlyMountOptions shortcut for readonly mount options
+	ReadOnlyMountOptions = MountOptions{
+		ReadOnly: true,
+	}
+)
+
+// MountOptions struct
+type MountOptions struct {
+	// ReadOnly
+	ReadOnly bool
+	// Limit size of read-write layer in Mib
+	Limit uint64
+}
+
 //Flister is the interface for the flist module
 type Flister interface {
 	// Mount mounts an flist located at url using the 0-db located at storage.
+	// MountOptions, can be nil, in that case falls to default, other wise
+	// use the provided values.
 	// Returns the path in the filesystem where the flist is mounted or an error
-	Mount(url string, storage string) (path string, err error)
+	Mount(url string, storage string, opts MountOptions) (path string, err error)
 
 	// Umount the flist mounted at path
 	Umount(path string) error
diff --git a/pkg/flist/flist.go b/pkg/flist/flist.go
index 7b01f63b..64530312 100644
--- a/pkg/flist/flist.go
+++ b/pkg/flist/flist.go
@@ -100,7 +100,7 @@ func New(root string, storage pkg.VolumeAllocater) pkg.Flister {
 }
 
 // Mount implements the Flister.Mount interface
-func (f *flistModule) Mount(url, storage string) (string, error) {
+func (f *flistModule) Mount(url, storage string, opts pkg.MountOptions) (string, error) {
 	sublog := log.With().Str("url", url).Str("storage", storage).Logger()
 	sublog.Info().Msg("request to mount flist")
 
@@ -119,10 +119,15 @@ func (f *flistModule) Mount(url, storage string) (string, error) {
 		sublog.Error().Err(err).Msg("fail to generate random id for the mount")
 		return "", err
 	}
-
-	path, err := f.storage.CreateFilesystem(rnd, 256*mib, pkg.SSDDevice)
-	if err != nil {
-		return "", errors.Wrap(err, "failed to create read-write subvolume for 0-fs")
+	var args []string
+	if !opts.ReadOnly {
+		path, err := f.storage.CreateFilesystem(rnd, opts.Limit*mib, pkg.SSDDevice)
+		if err != nil {
+			return "", errors.Wrap(err, "failed to create read-write subvolume for 0-fs")
+		}
+		args = append(args, "-backend", path)
+	} else {
+		args = append(args, "-ro")
 	}
 
 	mountpoint := filepath.Join(f.mountpoint, rnd)
@@ -132,8 +137,7 @@ func (f *flistModule) Mount(url, storage string) (string, error) {
 	pidPath := filepath.Join(f.pid, rnd) + ".pid"
 	logPath := filepath.Join(f.log, rnd) + ".log"
 
-	args := []string{
-		"-backend", path,
+	args = append(args,
 		"-cache", f.cache,
 		"-meta", flistPath,
 		"-storage-url", storage,
@@ -141,7 +145,7 @@ func (f *flistModule) Mount(url, storage string) (string, error) {
 		"-pid", pidPath,
 		"-log", logPath,
 		mountpoint,
-	}
+	)
 	sublog.Info().Strs("args", args).Msg("starting 0-fs daemon")
 	cmd := f.commander.Command("g8ufs", args...)
 
diff --git a/pkg/provision/container.go b/pkg/provision/container.go
index a52131b8..91c7785b 100644
--- a/pkg/provision/container.go
+++ b/pkg/provision/container.go
@@ -116,7 +116,7 @@ func containerProvisionImpl(ctx context.Context, reservation *Reservation) (Cont
 		Msg("assigned an IP")
 
 	log.Debug().Str("flist", config.FList).Msg("mounting flist")
-	mnt, err := flistClient.Mount(config.FList, config.FlistStorage)
+	mnt, err := flistClient.Mount(config.FList, config.FlistStorage, pkg.DefaultMountOptions)
 	if err != nil {
 		return ContainerResult{}, err
 	}
diff --git a/pkg/provision/zdb.go b/pkg/provision/zdb.go
index 4cc53f89..ba8a6022 100644
--- a/pkg/provision/zdb.go
+++ b/pkg/provision/zdb.go
@@ -220,7 +220,7 @@ func createZdbContainer(ctx context.Context, name string, mode pkg.ZDBMode, volu
 	)
 
 	slog.Debug().Str("flist", zdbFlistURL).Msg("mounting flist")
-	rootFS, err := flist.Mount(zdbFlistURL, "")
+	rootFS, err := flist.Mount(zdbFlistURL, "", pkg.ReadOnlyMountOptions)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/stubs/flist_stub.go b/pkg/stubs/flist_stub.go
index a0aad2b1..6037abb3 100644
--- a/pkg/stubs/flist_stub.go
+++ b/pkg/stubs/flist_stub.go
@@ -1,6 +1,9 @@
 package stubs
 
-import zbus "github.com/threefoldtech/zbus"
+import (
+	zbus "github.com/threefoldtech/zbus"
+	pkg "github.com/threefoldtech/zos/pkg"
+)
 
 type FlisterStub struct {
 	client zbus.Client
@@ -19,8 +22,8 @@ func NewFlisterStub(client zbus.Client) *FlisterStub {
 	}
 }
 
-func (s *FlisterStub) Mount(arg0 string, arg1 string) (ret0 string, ret1 error) {
-	args := []interface{}{arg0, arg1}
+func (s *FlisterStub) Mount(arg0 string, arg1 string, arg2 pkg.MountOptions) (ret0 string, ret1 error) {
+	args := []interface{}{arg0, arg1, arg2}
 	result, err := s.client.Request(s.module, s.object, "Mount", args...)
 	if err != nil {
 		panic(err)
diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go
index 3aae5d3b..e7f0b6a9 100644
--- a/pkg/upgrade/upgrade.go
+++ b/pkg/upgrade/upgrade.go
@@ -308,7 +308,7 @@ func (u *Upgrader) uninstall() error {
 func (u *Upgrader) applyUpgrade(version semver.Version, info flistInfo) error {
 	log.Info().Str("flist", u.Name()).Str("version", version.String()).Msg("start applying upgrade")
 
-	flistRoot, err := u.FLister.Mount(u.hub.MountURL(u.Name()), u.hub.StorageURL())
+	flistRoot, err := u.FLister.Mount(u.hub.MountURL(u.Name()), u.hub.StorageURL(), pkg.ReadOnlyMountOptions)
 	if err != nil {
 		return err
 	}


Test patch:
diff --git a/pkg/flist/flist_test.go b/pkg/flist/flist_test.go
index 07cf1743..e253a29e 100644
--- a/pkg/flist/flist_test.go
+++ b/pkg/flist/flist_test.go
@@ -125,7 +125,7 @@ func TestMountUnmount(t *testing.T) {
 	strg.On("CreateFilesystem", mock.Anything, uint64(256*mib), pkg.SSDDevice).
 		Return("/my/backend", nil)
 
-	mnt, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "")
+	mnt, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "", pkg.DefaultMountOptions)
 
 	require.NoError(t, err)
 
@@ -153,11 +153,11 @@ func TestIsolation(t *testing.T) {
 	strg.On("CreateFilesystem", mock.Anything, uint64(256*mib), pkg.SSDDevice).
 		Return("/my/backend", nil)
 
-	path1, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "")
+	path1, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "", pkg.DefaultMountOptions)
 	require.NoError(err)
 	args1 := cmder.m
 
-	path2, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "")
+	path2, err := flister.Mount("https://hub.grid.tf/thabet/redis.flist", "", pkg.DefaultMountOptions)
 	require.NoError(err)
 	args2 := cmder.m
 
diff --git a/pkg/provision/container_test.go b/pkg/provision/container_test.go
index a3f5f1cb..ccdb463f 100644
--- a/pkg/provision/container_test.go
+++ b/pkg/provision/container_test.go
@@ -110,7 +110,7 @@ func TestContainerProvisionNew(t *testing.T) {
 	client.On("Request",
 		"flist", zbus.ObjectID{Name: "flist", Version: "0.0.1"},
 		"Mount",
-		container.FList, container.FlistStorage).
+		container.FList, container.FlistStorage, pkg.DefaultMountOptions).
 		Return("/tmp/root", nil)
 
 	// once root is mounted, a final call to contd to run the container
@@ -206,7 +206,7 @@ func TestContainerProvisionWithMounts(t *testing.T) {
 	client.On("Request",
 		"flist", zbus.ObjectID{Name: "flist", Version: "0.0.1"},
 		"Mount",
-		container.FList, container.FlistStorage).
+		container.FList, container.FlistStorage, pkg.DefaultMountOptions).
 		Return("/tmp/root", nil)
 
 	// once root is mounted, a final call to contd to run the container
diff --git a/pkg/provision/zdb_test.go b/pkg/provision/zdb_test.go
index 88db326e..51ec1a38 100644
--- a/pkg/provision/zdb_test.go
+++ b/pkg/provision/zdb_test.go
@@ -166,7 +166,7 @@ func TestZDBProvisionNoMappingContainerDoesNotExists(t *testing.T) {
 	client.On("Request", "flist", zbus.ObjectID{Name: "flist", Version: "0.0.1"},
 		"Mount",
 		"https://hub.grid.tf/tf-autobuilder/threefoldtech-0-db-development.flist",
-		"").Return("/path/to/volume", nil)
+		"", pkg.ReadOnlyMountOptions).Return("/path/to/volume", nil)
 
 	client.On("Request", "network", zbus.ObjectID{Name: "network", Version: "0.0.1"},
 		"ZDBPrepare").Return("net-ns", nil)