diff --git a/cmds/contd/main.go b/cmds/contd/main.go index 0449351ef..e4534a339 100644 --- a/cmds/contd/main.go +++ b/cmds/contd/main.go @@ -4,7 +4,10 @@ import ( "context" "flag" "os" + "os/exec" + "time" + "github.com/cenkalti/backoff/v3" "github.com/rs/zerolog/log" "github.com/threefoldtech/zbus" @@ -38,6 +41,18 @@ func main() { version.ShowAndExit(false) } + // wait for shim-logs to be available before starting + log.Info().Msg("wait for shim-logs binary to be available") + bo := backoff.NewExponentialBackOff() + bo.MaxElapsedTime = 0 //forever + _ = backoff.RetryNotify(func() error { + _, err := exec.LookPath("shim-logs") + return err + // return fmt.Errorf("wait forever") + }, bo, func(err error, d time.Duration) { + log.Warn().Err(err).Msgf("shim-logs binary not found, retying in %s", d.String()) + }) + if err := os.MkdirAll(moduleRoot, 0750); err != nil { log.Fatal().Msgf("fail to create module root: %s", err) } diff --git a/go.mod b/go.mod index bef2da2ee..cfc2cbdb3 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/shirou/gopsutil v2.19.11+incompatible github.com/stretchr/testify v1.5.1 github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae - github.com/threefoldtech/tfexplorer v0.2.7-0.20200506105748-dd92c058d776 + github.com/threefoldtech/tfexplorer v0.3.1-0.20200520102753-5af0aaa729ab github.com/threefoldtech/zbus v0.1.3 github.com/urfave/cli v1.22.3 github.com/vishvananda/netlink v1.0.0 diff --git a/go.sum b/go.sum index 885f2388b..7762464c1 100644 --- a/go.sum +++ b/go.sum @@ -557,12 +557,8 @@ github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae h1:vgGSvdW5Lqg+I1aZOlG32uyE6xHpLdKhZzcTEktz5wM= github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae/go.mod h1:quDq6Se6jlGwiIKia/itDZxqC5rj6/8OdFyMMAwTxCs= github.com/threefoldtech/tfexplorer v0.2.5/go.mod h1:TugylEDgMNKk4ZIzee9PpVmIcLNLaRLdiXuhHTt/AR0= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200505125555-7d20b5212c0e h1:HqNiMBz0RpYg8RBDQl67soy2WPjAWHCBPzb7jl1Dtxc= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200505125555-7d20b5212c0e/go.mod h1:ozAe2OYR4ALp2PtyKT1A6UiTI+0ZcFU2UfUaRd1P5eE= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200505141628-4d7a0c749784 h1:CCyZTGGV7BVVIGDduxLtebFsVHxJt6i2Z7rq6ostfmU= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200505141628-4d7a0c749784/go.mod h1:ozAe2OYR4ALp2PtyKT1A6UiTI+0ZcFU2UfUaRd1P5eE= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200506105748-dd92c058d776 h1:wRAZ10WYNNADcuEfQ1YlL+UepxkPIyUhtSjFrj8Vugs= -github.com/threefoldtech/tfexplorer v0.2.7-0.20200506105748-dd92c058d776/go.mod h1:ozAe2OYR4ALp2PtyKT1A6UiTI+0ZcFU2UfUaRd1P5eE= +github.com/threefoldtech/tfexplorer v0.3.1-0.20200520102753-5af0aaa729ab h1:ScS48/VSgl3Eu25XGtex4z7ylGxc1KhHVyIRNc1LbmQ= +github.com/threefoldtech/tfexplorer v0.3.1-0.20200520102753-5af0aaa729ab/go.mod h1:ozAe2OYR4ALp2PtyKT1A6UiTI+0ZcFU2UfUaRd1P5eE= github.com/threefoldtech/zbus v0.1.3 h1:18DnIzximRbATle5ZdZz0i84n/bCYB8k/gkhr2dXayc= github.com/threefoldtech/zbus v0.1.3/go.mod h1:ZtiRpcqzEBJetVQDsEbw0p48h/AF3O1kf0tvd30I0BU= github.com/threefoldtech/zos v0.2.4-rc2/go.mod h1:7A2oflcmSVsHFC4slOcydWgJyFBMFMH9wsaTRv+CnTA= diff --git a/pkg/flist.go b/pkg/flist.go index 5140afd93..faa5823ff 100644 --- a/pkg/flist.go +++ b/pkg/flist.go @@ -9,6 +9,7 @@ var ( DefaultMountOptions = MountOptions{ ReadOnly: false, Limit: 256, //Mib + Type: SSDDevice, } //ReadOnlyMountOptions shortcut for readonly mount options @@ -23,6 +24,8 @@ type MountOptions struct { ReadOnly bool // Limit size of read-write layer in Mib Limit uint64 + // Type of disk to use + Type DeviceType } //Flister is the interface for the flist module diff --git a/pkg/flist/flist.go b/pkg/flist/flist.go index d785b91a6..21ca5e78c 100644 --- a/pkg/flist/flist.go +++ b/pkg/flist/flist.go @@ -177,10 +177,18 @@ func (f *flistModule) mount(name, url, storage string, opts pkg.MountOptions) (s var args []string if !opts.ReadOnly { - path, err := f.storage.CreateFilesystem(name, opts.Limit*mib, pkg.SSDDevice) + sublog.Info().Msgf("check if subvolume %s already exists", name) + // check if the filesystem doesn't already exists + path, err := f.storage.Path(name) if err != nil { - return "", errors.Wrap(err, "failed to create read-write subvolume for 0-fs") + sublog.Info().Msgf("create new subvolume %s", name) + // and only create a new one if it doesn't exist + path, err = f.storage.CreateFilesystem(name, opts.Limit*mib, opts.Type) + 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") diff --git a/pkg/provision/primitives/container.go b/pkg/provision/primitives/container.go index 703339f1a..52a917f62 100644 --- a/pkg/provision/primitives/container.go +++ b/pkg/provision/primitives/container.go @@ -74,6 +74,10 @@ type ContainerCapacity struct { CPU uint `json:"cpu"` // Memory in MiB Memory uint64 `json:"memory"` + //DiskType is the type of disk to use for root fs + DiskType pkg.DeviceType `json:"disk_type"` + // DiskSize of the root fs in MiB + DiskSize uint64 `json:"disk_size"` } func (p *Provisioner) containerProvision(ctx context.Context, reservation *provision.Reservation) (interface{}, error) { @@ -109,8 +113,18 @@ func (p *Provisioner) containerProvisionImpl(ctx context.Context, reservation *p } log.Debug().Str("flist", config.FList).Msg("mounting flist") + + rootfsMntOpt := pkg.MountOptions{ + Limit: config.Capacity.DiskSize, + ReadOnly: false, + Type: config.Capacity.DiskType, + } + if rootfsMntOpt.Limit == 0 || rootfsMntOpt.Type == "" { + rootfsMntOpt = pkg.DefaultMountOptions + } + var mnt string - mnt, err = flistClient.Mount(config.FList, config.FlistStorage, pkg.DefaultMountOptions) + mnt, err = flistClient.NamedMount(reservation.ID, config.FList, config.FlistStorage, rootfsMntOpt) if err != nil { return ContainerResult{}, err } @@ -218,7 +232,7 @@ func (p *Provisioner) containerProvisionImpl(ctx context.Context, reservation *p Entrypoint: config.Entrypoint, Interactive: config.Interactive, CPU: config.Capacity.CPU, - Memory: config.Capacity.Memory * 1024 * 1024, + Memory: config.Capacity.Memory * mib, Logs: config.Logs, StatsAggregator: config.StatsAggregator, }, diff --git a/pkg/provision/primitives/converter.go b/pkg/provision/primitives/converter.go index b88c93831..800424925 100644 --- a/pkg/provision/primitives/converter.go +++ b/pkg/provision/primitives/converter.go @@ -29,8 +29,10 @@ func ContainerToProvisionType(c workloads.Container, reservationID string) (Cont Logs: make([]logger.Logs, len(c.Logs)), StatsAggregator: make([]stats.Aggregator, len(c.StatsAggregator)), Capacity: ContainerCapacity{ - CPU: uint(c.Capacity.Cpu), - Memory: uint64(c.Capacity.Memory), + CPU: uint(c.Capacity.Cpu), + Memory: uint64(c.Capacity.Memory), + DiskType: pkg.DeviceType(c.Capacity.DiskType), + DiskSize: uint64(c.Capacity.DiskSize), }, } diff --git a/pkg/provision/primitives/kubernetes.go b/pkg/provision/primitives/kubernetes.go index a9940b12f..f0dce8a01 100644 --- a/pkg/provision/primitives/kubernetes.go +++ b/pkg/provision/primitives/kubernetes.go @@ -91,7 +91,7 @@ func (p *Provisioner) kubernetesProvisionImpl(ctx context.Context, reservation * if err != nil { return result, errors.Wrap(err, "could not mount k3os flist") } - // In case of future errrors in the provisioning make sure we clean up + // In case of future errors in the provisioning make sure we clean up defer func() { if err != nil { _ = flist.Umount(imagePath)