Skip to content

feat: Add 'volume import' command#245

Merged
jedevc merged 5 commits intostagingfrom
craciunoiuc/add-volume-import
Apr 21, 2026
Merged

feat: Add 'volume import' command#245
jedevc merged 5 commits intostagingfrom
craciunoiuc/add-volume-import

Conversation

@craciunoiuc
Copy link
Copy Markdown
Member

@craciunoiuc craciunoiuc commented Apr 3, 2026

This adds initial support for volume importing. As before, only CPIO files are supported for importing due to how the "backend" of this is built.

To add to this, only files and directories are supported right now. I could not figure out how to correctly split the dockerfile implementation to make it stop before creating the OCI archive using imagespec, as I needed it to give me a .cpio file.
Dockerfiles also work now.

To make this fully work, proto needs to be updated and the delete_on_stop flag needs to be renamed to delete-on-stop.
Switched to new way of providing features that works.
Sdk fixed.

Finally, I don't really like how things sit but I couldn't find a better way to break things apart whilst also keeping the general repo structure (aka not refactoring everything 😈)
I did the refactoring hehe.

tldr: if you give it no --source it will use the workdir and assume it's a Kraftfile in there (or fail if not)
Removed.

If you give it a --source it uses that, be it a CPIO (directly uses it), or Directory (Packages it), or Dockerfile (Builds it).

TODO: Regenerate tests before merging

Blocked on: https://github.com/unikraft-cloud/platform/pull/705
Closes: TOOL-694

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an initial unikraft volume import command to import local data into an existing Unikraft Cloud volume by packaging the source into a CPIO archive and streaming it to a temporary “volimport” instance over TLS.

Changes:

  • Introduces volume import CLI command that builds/uses a CPIO archive and streams it to a per-volume import instance.
  • Adds internal/builder.BuildImportRootfs helper to normalize an import source (directory vs existing CPIO).
  • Implements a TLS streaming protocol in internal/builder/cpio for sending CPIO entries and handling ack/stop responses.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
internal/cmd/volumes.go Adds volume import command, instance spawning, TLS connect, and auth token generation.
internal/builder/import.go Adds helper to build/validate an importable CPIO archive from a directory or existing CPIO file.
internal/builder/cpio/cpio.go Adds CPIO magic detection and the TLS streaming/ack protocol implementation.
cmd/unikraft/volumes_test.go Extends CLI help smoke test to include volume import --help.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/builder/cpio/cpio.go Outdated
Comment thread internal/builder/cpio/cpio.go Outdated
Comment thread internal/builder/cpio/cpio.go Outdated
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch 4 times, most recently from 75717cb to dd16f28 Compare April 7, 2026 09:32
@craciunoiuc craciunoiuc marked this pull request as ready for review April 7, 2026 09:50
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/builder/cpio/cpio.go Outdated
Comment thread internal/builder/cpio/cpio.go Outdated
Comment thread internal/builder/rootfs.go Outdated
Comment thread internal/builder/import.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch from dd16f28 to ac5d87c Compare April 15, 2026 14:55
@craciunoiuc craciunoiuc marked this pull request as draft April 15, 2026 14:55
@craciunoiuc
Copy link
Copy Markdown
Member Author

I split all the suggested changes into separate commits. I will need to squash some of them up before it's ready to review again.

Currently a bit broken as the imgspec does not return the path to the computer layer.

Also rootfs building does not work without dockerfiles. (aka with directories or files)

With these out of the way it should work again.

@jedevc
Copy link
Copy Markdown
Member

jedevc commented Apr 15, 2026

Currently a bit broken as the imgspec does not return the path to the computer layer.

Why do you need the "computer layer"? Do you need to open the file? If so, you can call Open. What specifically needs the path here?

Also rootfs building does not work without dockerfiles. (aka with directories or files)

Indeed 🎉 I was hoping this was one of the things you might take a look at at some point, or even as part of this (though maybe in a separate PR).

@craciunoiuc
Copy link
Copy Markdown
Member Author

I was hoping this was one of the things you might take a look at at some point

Hmm, then something is weird, because you told me to revert the file/directory/dockerfile detection that I previously had. (which is why I did them as commits on top instead of overwriting hehe.

Why do you need the "computer layer"?

Lol, not sure how I wrote that. I wanted to say the rootfs layer. I was hoping the imagespec directory would give me to path to the file if I call images[0].Initrd.Path() on it for examples. But it seems that it's always empty.

@jedevc
Copy link
Copy Markdown
Member

jedevc commented Apr 15, 2026

The detection should exist, yes, but it should be extracted - it shouldn't be done just for the volume imports. We should have one reusable function that does "pass this thing in, and build a rootfs from it". We may need to rework those functions and everything so that the signatures all work out. What we need to avoid is rewriting the same detection everywhere.

@jedevc
Copy link
Copy Markdown
Member

jedevc commented Apr 15, 2026

Path() is not documented well, but it's the path inside the tarball. e.g. for a packaged kernel, the kernel lives inside the tarball at /unikraft/bin/kernel for example. Path() says which of those it's at.

Looking at how it's used actually... we could remove that method entirely.

@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch from ac5d87c to 3679e46 Compare April 16, 2026 16:22
Comment thread internal/builder/import.go Outdated
Comment thread cmd/unikraft/volumes_test.go
Comment thread internal/builder/cpio/cpio.go Outdated
Comment thread internal/builder/rootfs.go Outdated
Comment thread internal/builder/rootfs.go Outdated
Comment thread internal/cmd/volumes.go
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/volimport/volimport.go Outdated
@craciunoiuc
Copy link
Copy Markdown
Member Author

All comments make sense, will address, next time you see this PR it will have the changed commit history

@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch 3 times, most recently from dd5b0a5 to 2f7ab57 Compare April 17, 2026 14:14
@craciunoiuc craciunoiuc requested a review from Copilot April 17, 2026 14:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 19 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cmd/volumes.go Outdated
Comment thread internal/cmd/volumes.go
Comment thread internal/volimport/copy.go
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go Outdated
Comment thread internal/builder/rootfs.go
@craciunoiuc
Copy link
Copy Markdown
Member Author

^ Will do monday.

@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch 3 times, most recently from 7dd8b9d to 93c55ad Compare April 20, 2026 08:19
@craciunoiuc
Copy link
Copy Markdown
Member Author

Integration is really weird, at least 2-3 things related to the server itself

PR should be ready

@craciunoiuc craciunoiuc requested a review from jedevc April 20, 2026 08:23
Comment thread cmd/unikraft/testdata/TestGolden/volumes/import/dir
Copy link
Copy Markdown
Member

@jedevc jedevc left a comment

Choose a reason for hiding this comment

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

Only nits, happy to merge when they're resolved.

Comment thread internal/builder/rootfs.go Outdated
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/build.go Outdated
RootfsTypeErofs RootfsType = "erofs"
RootfsTypeDir RootfsType = "dir"
// Unused for now, but may be useful in ROMs
RootfsTypeFile RootfsType = "file"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should remove this for now if it's not being used.

} else {
return BuildOpts{}, fmt.Errorf("unable to determine rootfs type for source %q", kf.Rootfs.Source)
sourcePath := filepath.Join(dir, kf.Rootfs.Source)
typ, err := DetectRootfsType(sourcePath)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you follow-up with a PR to x/kraftfile to add a field for this explicitly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

shouldn't I do this before, so I can rebase this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would keep the detection logic here for when that field is empty. Up to you on ordering, I have no preference.

@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch from 5a0540f to 3bc965e Compare April 20, 2026 19:17
Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
Implements 'volimport' instance lifecycle helpers.
Also adds the communication protocol with the instance.
Finally add a rootfs build helper for formatting properly.

Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch 3 times, most recently from 76a04f1 to 883907c Compare April 21, 2026 06:39
Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/add-volume-import branch from 883907c to eb29345 Compare April 21, 2026 06:57
@craciunoiuc craciunoiuc marked this pull request as ready for review April 21, 2026 07:01
@craciunoiuc craciunoiuc requested a review from jedevc April 21, 2026 07:01
@craciunoiuc
Copy link
Copy Markdown
Member Author

finally, it feels like 1 morbillion years have passed

Signed-off-by: Justin Chadwell <justin@unikraft.com>
Copy link
Copy Markdown
Member

@jedevc jedevc left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Justin Chadwell justin@unikraft.com
Approved-by: Justin Chadwell justin@unikraft.com

@jedevc jedevc merged commit fadc971 into staging Apr 21, 2026
9 checks passed
@jedevc jedevc deleted the craciunoiuc/add-volume-import branch April 21, 2026 08:22
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.

3 participants