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

nydus-image: add backend-config support to nydus-image unpack #1082

Merged
merged 1 commit into from
Feb 20, 2023

Conversation

loheagn
Copy link
Contributor

@loheagn loheagn commented Feb 15, 2023

The nydus-image unpack only support reading nydus blob from the blob files on local machine (by the argument blob) by now. This patch adds a new argument backend-config to this command to allow nydus-image unpack to read blob data from all kinds of backends.

@loheagn loheagn requested a review from a team as a code owner February 15, 2023 06:35
@loheagn loheagn requested review from jiangliu, changweige and adamqqqplay and removed request for a team February 15, 2023 06:35
@anolis-bot
Copy link
Collaborator

@loheagn , a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/50984

@loheagn loheagn changed the title Add backend-config support to nydus-image unpack nydus-image: add backend-config support to nydus-image unpack Feb 15, 2023
@anolis-bot
Copy link
Collaborator

@loheagn , the title has been updated, so a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/50989

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd❌ FAIL

Sorry, your test job failed. Please get the details in the link.

@anolis-bot
Copy link
Collaborator

@loheagn , the code has been updated, so a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/50990

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd✅ SUCCESS
compile ctr remote✅ SUCCESS
compile nydus snapshotter✅ SUCCESS
run container with rafs✅ SUCCESS
run container with zran✅ SUCCESS

Congratulations, your test job passed!

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd✅ SUCCESS
compile ctr remote✅ SUCCESS
compile nydus snapshotter✅ SUCCESS
run container with rafs✅ SUCCESS
run container with zran✅ SUCCESS

Congratulations, your test job passed!

@jiangliu
Copy link
Collaborator

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@loheagn
Copy link
Contributor Author

loheagn commented Feb 15, 2023

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

@jiangliu
Copy link
Collaborator

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

@loheagn
Copy link
Contributor Author

loheagn commented Feb 15, 2023

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.

For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

@jiangliu
Copy link
Collaborator

jiangliu commented Feb 15, 2023

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.

For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

Can we let nydus-image to handle the bootstrap part too?
That's a feature I expect, then nydus-image can process remote images.

@loheagn
Copy link
Contributor Author

loheagn commented Feb 15, 2023

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.
For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

Can we let nydus-image to handle the bootstrap part too? That's a feature I expect, then nydus-image can process remote images.

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.
For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

Can we let nydus-image to handle the bootstrap part too? That's a feature I expect, then nydus-image can process remote images.

@jiangliu Yes, I think we can.

We need to implement the logic of extracting the bootstrap and blob data from the whole nydus image layer (which is implemented in nydus-snapshotter by now) and let the caller tell nydus-image the loacation of the image layer by some argument (may be --image-path).

What's your option? @imeoer

@jiangliu
Copy link
Collaborator

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.
For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

Can we let nydus-image to handle the bootstrap part too? That's a feature I expect, then nydus-image can process remote images.

How about using "-C, --config " instead? We are going to switch from "--backend-config" to "--config" and "--backend-config" will get deprecated.

@jiangliu But I think this will be conflict with the backend in the Config when load rafs. https://github.com/dragonflyoss/image-service/blob/master/rafs/src/metadata/mod.rs#L685

Are you going to support this usage scenario?

  1. nydus meta blob has already been extracted to a local directory
  2. nydus data blobs haven't been downloaded to the local directory

Yes.
For example, by now, when we use the coverter.Unpack method in nydus-snapshotter to unpack a nydus image layer, we need to extract both the bootstrap part and the blob data part to the local disk first to allow the nydus-image to read to blob data (use the localfs backend). But with this patch, we can just need to extract the bootstrap part and set up a local http server to serve the blob data part. Then the backend-config can be used to pass the information about this local http server.

Can we let nydus-image to handle the bootstrap part too? That's a feature I expect, then nydus-image can process remote images.

@jiangliu Yes, I think we can.

We need to implement the logic of extracting the bootstrap and blob data from the whole nydus image layer (which is implemented in nydus-snapshotter by now) and let the caller tell nydus-image the loacation of the image layer by some argument (may be --image-path).

What's your option? @imeoer

We may discuss offline. I hope we can enhance nydus-image to directly handle remote image, the same to nydusd.

@jiangliu
Copy link
Collaborator

Does this work for you?

nydus-image unpack -C nydusd.conf --outputb image.tar.gz path/to/bootstrap.file

@@ -250,6 +250,7 @@ pub struct BackendConfigV2 {
/// Configuration for container registry backend.
pub registry: Option<RegistryConfig>,
/// Configuration for local http proxy.
#[serde(rename = "http-proxy")]
pub http_proxy: Option<HttpProxyConfig>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This deserves a dedicated PR:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the pr #1086 .

@@ -17,16 +17,19 @@ extern crate lazy_static;
use std::fs::{self, metadata, DirEntry, File, OpenOptions};
use std::os::unix::fs::FileTypeExt;
use std::path::{Path, PathBuf};
use std::result::Result::Ok;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may be unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Fixed :)

@anolis-bot
Copy link
Collaborator

@loheagn , the code has been updated, so a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/51269

@loheagn
Copy link
Contributor Author

loheagn commented Feb 16, 2023

Does this work for you?

nydus-image unpack -C nydusd.conf --outputb image.tar.gz path/to/bootstrap.file

NO. The argument --bootstrap is required.

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd✅ SUCCESS
compile ctr remote✅ SUCCESS
compile nydus snapshotter✅ SUCCESS
run container with rafs✅ SUCCESS
run container with zran✅ SUCCESS

Congratulations, your test job passed!

@anolis-bot
Copy link
Collaborator

@loheagn , the code has been updated, so a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/51285


Ok(backend)
}

fn get_blob_id(matches: &ArgMatches) -> Result<String> {
let mut blob_id = String::new();

Copy link

Choose a reason for hiding this comment

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

our review

  1. The code contains unused imports like nix and nydus_storage.
  2. The code is missing type annotations, which makes it difficult to understand what is going on in the code.
  3. The code does not have any comments, which can help explain the purpose of the code.
  4. In the prepare_cmd_args function, the argument for the backend-config should be made required.
  5. In the get_backend function, the backend-config argument should be checked for validity before being used.
  6. In the get_blob_id function, the blob_id variable should be initialized with a meaningful value before being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are so smart 💯

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd✅ SUCCESS
compile ctr remote✅ SUCCESS
compile nydus snapshotter✅ SUCCESS
run container with rafs✅ SUCCESS
run container with zran✅ SUCCESS

Congratulations, your test job passed!

The `nydus-image unpack` only support reading nydus blob from the blob files on local machine (by the argument `blob`) by now. This patch adds a new argument `backend-config` to this command to allow `nydus-image unpack` to read blob data from all kinds of backends.

Signed-off-by: Nan Li <loheagn@icloud.com>
@anolis-bot
Copy link
Collaborator

@loheagn , the code has been updated, so a new test job has been submitted. Please wait in patience. The test job url: https://tone.openanolis.cn/ws/nrh4nnio/test_result/51290


Ok(backend)
}

fn get_blob_id(matches: &ArgMatches) -> Result<String> {
let mut blob_id = String::new();

Copy link

Choose a reason for hiding this comment

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

with a brief introduction about the code,

The code is a part of an application written in Rust programming language. It implements a Command struct and Command trait which provides functionality for configuring backend from config file, importing chunk dictionary and unpack metadata. The code is also responsible for validating user provided arguments such as --output and --blob.

Now, let's move on to the code review.

First, the code contains some missing error handling for the LocalFs::new() method call. This should be added to prevent any unexpected errors.

Second, it would be better to use pattern matching when checking the blob argument instead of using if-else statements. This will make the code more readable and maintainable.

Third, the get_backend() function can be simplified by using the shorthand notation for destructuring the Option type. This will make the code more concise.

Fourth, the get_blob_id() method can be improved by using the Result type instead of returning a String. This will help in better error handling.

Finally, it would be better to use the Result combinators such as map_err() and map() to improve the readability of the code and make it more concise.

@anolis-bot
Copy link
Collaborator

@loheagn , The CI test is completed, please check result:

Test CaseTest Result
build rust golang image✅ SUCCESS
compile nydusd✅ SUCCESS
compile ctr remote✅ SUCCESS
compile nydus snapshotter✅ SUCCESS
run container with rafs✅ SUCCESS
run container with zran✅ SUCCESS

Congratulations, your test job passed!

@jiangliu
Copy link
Collaborator

Does this work for you?

nydus-image unpack -C nydusd.conf --outputb image.tar.gz path/to/bootstrap.file

NO. The argument --bootstrap is required.

With nydus 2.2, the "--bootstrap" option for nydus-image unpack should be optional:)
I simplified it by making "--bootstrap" optional.

@imeoer imeoer merged commit aea56eb into dragonflyoss:master Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants