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

feat: add new disk service #515

Merged
merged 3 commits into from
Aug 22, 2022
Merged

feat: add new disk service #515

merged 3 commits into from
Aug 22, 2022

Conversation

richardcase
Copy link
Member

What this PR does / why we need it:

This change adds a new port for a "disk service" that will be used to
create disk images (i.e. img/iso files). An infrastructure
implementation has been added using godisk.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Relates #417

Special notes for your reviewer:

Note: this isn't used by anything in this change. But it will be used in
the future with the Cloud Hypervisor implementation.

Checklist:

  • squashed commits into logical changes
  • adds unit tests
  • adds or updates e2e tests

@richardcase richardcase added the kind/feature New feature or request label Aug 19, 2022
//Path is the filesystem path of where to create the disk.
Path string
// Size is how big the disk should be. It uses human readable formats
// suck as 8Mb, 10Kb.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// suck as 8Mb, 10Kb.
// such as 8Mb, 10Kb.

Copy link
Member Author

Choose a reason for hiding this comment

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

My code sucks 🤣

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

Comment on lines 38 to 54
if _, err := s.fs.Stat(input.Path); err == nil {
if removeErr := s.fs.Remove(input.Path); removeErr != nil {
return fmt.Errorf("removing disk %s: %w", input.Path, removeErr)
}
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 explain this bit here: why do we delete whatever it at the input path first? it is to clean whatever is there before we create over it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep it's basically that. If the disk image exists already then delete and we will re-create.

What do you think to that default behaviour? Should i make it configurable? Perhaps add an option to DiskCreateInput valled OverwriteExisting?

Copy link
Member

Choose a reason for hiding this comment

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

maybe.

worst case is someone sets Path to something they should not and it is erased. having it error unless told explicitly to overwrite may be useful

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, changing now...

Copy link
Member Author

Choose a reason for hiding this comment

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

@Callisto13 - all changed.

return fmt.Errorf("creating disk %s: %w", input.Path, err)
}

createdDisk.LogicalBlocksize = 512
Copy link
Member

Choose a reason for hiding this comment

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

can we have that in a const?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that would've been a const to start with 👍

Comment on lines 88 to 92
if err != nil {
return err
}

return nil
Copy link
Member

Choose a reason for hiding this comment

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

could be return err but maybe that would read weird

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 like it, a lot neater.

Comment on lines -90 to +92
func appPorts(repo ports.MicroVMRepository, prov ports.MicroVMService, es ports.EventService, is ports.IDService, ns ports.NetworkService, ims ports.ImageService, fs afero.Fs) *ports.Collection {
func appPorts(repo ports.MicroVMRepository, prov ports.MicroVMService, es ports.EventService, is ports.IDService, ns ports.NetworkService, ims ports.ImageService, fs afero.Fs, ds ports.DiskService) *ports.Collection {
Copy link
Member

Choose a reason for hiding this comment

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

hrmmm could do with a way of shrinking this signature

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 did link about that but thought as this is for DI i wouldn't bother....it can get a bit messy with wire.

This change adds a new port for a "disk service" that will be used to
create disk images (i.e. img/iso files). An infrastructure
implemenetation has been added using godisk.

Note: this isn't used by anything in this change. But it will be used in
the future with the Cloud Hypervisor implementation.

Signed-off-by: Richard Case <[email protected]>
Copy link
Member

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

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

LGTM

@richardcase richardcase merged commit adddb41 into liquidmetal-dev:main Aug 22, 2022
@richardcase richardcase deleted the disk_service branch August 22, 2022 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants