-
Notifications
You must be signed in to change notification settings - Fork 247
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
Conversation
6362511
to
9f8471c
Compare
drivers/ostree/driver.go
Outdated
} | ||
|
||
_, err = os.Stat(repoLocation) | ||
if err != nil { |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
if err := idtools.MkdirAllAndChown(repoLocation, 0700, rootIDs); err != nil { | ||
return nil, err | ||
} | ||
err := exec.Command("ostree", fmt.Sprintf("--repo=%s", repoLocation), "init").Run() |
There was a problem hiding this comment.
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 {
}
drivers/ostree/driver.go
Outdated
idMappings := idtools.NewIDMappingsFromMaps(uidMaps, gidMaps) | ||
rootIDs := idMappings.RootPair() | ||
if err := idtools.MkdirAllAndChown(repoLocation, 0700, rootIDs); err != nil { | ||
return nil, err |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
|
||
repo, err := otbuiltin.OpenRepo(repoLocation) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
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?
drivers/ostree/driver.go
Outdated
commitOpts.Parent = "0000000000000000000000000000000000000000000000000000000000000000" | ||
branch := fmt.Sprintf("ocilayer/%s", id) | ||
|
||
_, err = d.repo.Commit(root, branch, commitOpts) |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
} | ||
|
||
err = system.EnsureRemoveAll(root) | ||
if err != nil { |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
} | ||
|
||
checkoutOpts := otbuiltin.NewCheckoutOptions() | ||
err = otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts) |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
checkoutOpts := otbuiltin.NewCheckoutOptions() | ||
err = otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful error?
drivers/ostree/driver.go
Outdated
|
||
_, err = d.repo.CommitTransaction() | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usefull error?
drivers/ostree/driver.go
Outdated
if convert { | ||
err := d.convertToOSTree(root, id) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useful error?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking.
52c18cf
to
daaf5f9
Compare
@rhatdan, I've pushed another version with all the comments addressed ⬆️ |
drivers/ostree/driver.go
Outdated
} | ||
|
||
func getDir(home, id string) string { | ||
return fmt.Sprintf("%s/%s/diff", home, id) |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
// 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) |
There was a problem hiding this comment.
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.
drivers/ostree/driver.go
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Wrapf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowercase
drivers/ostree/driver.go
Outdated
} | ||
|
||
if _, err := d.repo.CommitTransaction(); err != nil { | ||
return fmt.Errorf("Could not complete the OSTree transaction: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
drivers/ostree/driver.go
Outdated
} | ||
|
||
if err := system.EnsureRemoveAll(root); err != nil { | ||
return err |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giuseppe What about this?
There was a problem hiding this comment.
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()
drivers/ostree/driver.go
Outdated
|
||
checkoutOpts := otbuiltin.NewCheckoutOptions() | ||
if err := otbuiltin.Checkout(d.repoLocation, root, branch, checkoutOpts); err != nil { | ||
return fmt.Errorf("Could not checkout from OSTree: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Wrapf
drivers/ostree/driver.go
Outdated
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) |
There was a problem hiding this comment.
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")
drivers/ostree/driver.go
Outdated
|
||
// Get returns the directory for the given id. | ||
func (d *Driver) Get(id, mountLabel string) (string, error) { | ||
path, err := d.overlay.Get(id, mountLabel) |
There was a problem hiding this comment.
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)
drivers/ostree/driver_stub.go
Outdated
} | ||
|
||
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { | ||
return nil, fmt.Errorf("ostree driver not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use errors.Errorf()
6527f1b
to
ba78a99
Compare
thanks for the quick review. I've addressed the new comments |
@nalind Should we add a new driver or enhance the Overlay driver to use OSTREE via an option? |
ba78a99
to
62c45db
Compare
@giuseppe Tests are failing. |
e5fdfba
to
40f7a37
Compare
@rhatdan fixed. I needed to set the mtime to the EPOCH so it doesn't trigger a difference when OSTree is used. |
Fixed in the last version I've pushed |
05bfb70
to
82a6eb2
Compare
LGTM |
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
rebased |
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]>
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]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
@rhatdan fine to merge this? |
Going to finally merge this one. |
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.