Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ostree: new option for the overlay driver #137

Merged
merged 10 commits into from
Jul 5, 2018

Conversation

giuseppe
Copy link
Member

@giuseppe giuseppe commented Nov 14, 2017

if ostree_repo is specified, then any layer is first committed to the specified ostree repository and then checkout out to the same location so that files are deduplicated using OSTree hardlinks.

The exclude_ostree BUILDTAG can be used to disable ostree support.

@giuseppe giuseppe force-pushed the ostree-storage branch 15 times, most recently from 6362511 to 9f8471c Compare November 14, 2017 14:42
@rhatdan rhatdan self-requested a review November 15, 2017 14:40
}

_, err = os.Stat(repoLocation)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you check if this err is enoexist otherwise return the error.

if err := idtools.MkdirAllAndChown(repoLocation, 0700, rootIDs); err != nil {
return nil, err
}
err := exec.Command("ostree", fmt.Sprintf("--repo=%s", repoLocation), "init").Run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit do this on same line
if err := exec.Command("ostree", fmt.Sprintf("--repo=%s", repoLocation), "init").Run(); err != nil {
}

idMappings := idtools.NewIDMappingsFromMaps(uidMaps, gidMaps)
rootIDs := idMappings.RootPair()
if err := idtools.MkdirAllAndChown(repoLocation, 0700, rootIDs); err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap this error with something helpful to the user.


repo, err := otbuiltin.OpenRepo(repoLocation)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this give a use fule error message?

commitOpts.Parent = "0000000000000000000000000000000000000000000000000000000000000000"
branch := fmt.Sprintf("ocilayer/%s", id)

_, err = d.repo.Commit(root, branch, commitOpts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; Put this in one line.

}

err = system.EnsureRemoveAll(root)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; Put this in one line.

}

checkoutOpts := otbuiltin.NewCheckoutOptions()
err = otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; Put this in one line.

checkoutOpts := otbuiltin.NewCheckoutOptions()
err = otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful error?


_, err = d.repo.CommitTransaction()
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usefull error?

if convert {
err := d.convertToOSTree(root, id)
if err != nil {
return err
Copy link
Member

@rhatdan rhatdan Nov 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppe Does convertToOSTRee give a useful error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is defined in this module and it already gives useful errors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking.

@giuseppe giuseppe force-pushed the ostree-storage branch 3 times, most recently from 52c18cf to daaf5f9 Compare November 15, 2017 17:45
@giuseppe
Copy link
Member Author

@rhatdan, I've pushed another version with all the comments addressed ⬆️

}

func getDir(home, id string) string {
return fmt.Sprintf("%s/%s/diff", home, id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to use filepath.Join() for this type of thing.

// Create prepares the filesystem for the OSTREE driver and copies the directory for the given id under the parent.
func (d *Driver) convertToOSTree(root, id string) error {
if _, err := d.repo.PrepareTransaction(); err != nil {
return fmt.Errorf("Could not prepare the OSTree transaction: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use
errors.Wrapf(err, "could not prepare the OSTree transaction")

Standard is to have errors start with lowercase. I believe.

branch := fmt.Sprintf("ocilayer/%s", id)

if _, err := d.repo.Commit(root, branch, commitOpts); err != nil {
return fmt.Errorf("Could not commit the layer: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrapf.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase

}

if _, err := d.repo.CommitTransaction(); err != nil {
return fmt.Errorf("Could not complete the OSTree transaction: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}

if err := system.EnsureRemoveAll(root); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrapf(err, "failed to remove %q", root)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppe What about this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the code and it already gives a similar error message, so I think it would be duplicated return errors.Wrapf(e, "error while removing %s", dir). In some other cases it returns directly the error from os.RemoveAll()


checkoutOpts := otbuiltin.NewCheckoutOptions()
if err := otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts); err != nil {
return fmt.Errorf("Could not checkout from OSTree: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrapf

func (d *Driver) Remove(id string) error {
branch := fmt.Sprintf("ocilayer/%s", id)
if err := exec.Command("ostree", fmt.Sprintf("--repo=%s", d.repoLocation), "refs", "--delete", branch).Run(); err != nil {
return fmt.Errorf("Could not delete OSTree branch: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrapf("Could not delete OSTree branch")


// Get returns the directory for the given id.
func (d *Driver) Get(id, mountLabel string) (string, error) {
path, err := d.overlay.Get(id, mountLabel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return d.overlay.Get(id, mountLabel)

}

func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
return nil, fmt.Errorf("ostree driver not supported")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use errors.Errorf()

@giuseppe giuseppe force-pushed the ostree-storage branch 5 times, most recently from 6527f1b to ba78a99 Compare November 16, 2017 07:29
@giuseppe
Copy link
Member Author

thanks for the quick review. I've addressed the new comments

@rhatdan
Copy link
Member

rhatdan commented Nov 16, 2017

@nalind Should we add a new driver or enhance the Overlay driver to use OSTREE via an option?
overlay.

@rhatdan
Copy link
Member

rhatdan commented Jun 22, 2018

@giuseppe Tests are failing.

@giuseppe giuseppe force-pushed the ostree-storage branch 5 times, most recently from e5fdfba to 40f7a37 Compare June 22, 2018 16:12
@giuseppe
Copy link
Member Author

@rhatdan fixed. I needed to set the mtime to the EPOCH so it doesn't trigger a difference when OSTree is used.

@giuseppe
Copy link
Member Author

giuseppe commented Jun 22, 2018

the only missing part that I would like to work on as a follow-up is dropping the ostree CLI usage and add the missing features to the go bindings (delete branch and init repository).

Fixed in the last version I've pushed

@giuseppe giuseppe force-pushed the ostree-storage branch 2 times, most recently from 05bfb70 to 82a6eb2 Compare June 23, 2018 10:50
@rhatdan
Copy link
Member

rhatdan commented Jun 25, 2018

LGTM
@nalind PTAL

giuseppe added 2 commits June 29, 2018 17:58
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe
Copy link
Member Author

rebased

giuseppe added 8 commits June 29, 2018 18:47
usage example:

skopeo copy docker-daemon:busybox:latest containers-storage:\[overlay2@/var/lib/containers/storage+/var/run/containers/storage:overlay2.ostree_repo=/var/lib/containers/storage/overlay2/ostree/.repo,overlay2.override_kernel_check=1\]\busybox

Signed-off-by: Giuseppe Scrivano <[email protected]>
It is needed to use an OSTree repository (either directly or as a parent
repository) that is not under the storage home directory.

Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
so it won't be different once added to OSTree.

Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe
Copy link
Member Author

giuseppe commented Jul 4, 2018

@rhatdan fine to merge this?

@rhatdan
Copy link
Member

rhatdan commented Jul 5, 2018

Going to finally merge this one.

@rhatdan rhatdan merged commit 9cbb6cb into containers:master Jul 5, 2018
@runcom runcom mentioned this pull request Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants