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

Image-rs & CDH | Refactoring and use the same ImageClient #708

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Xynnn007
Copy link
Member

@Xynnn007 Xynnn007 commented Sep 6, 2024

This PR organizes the code of image-rs to make it more modular and allows CDH and image-rs to share the same image pull configuration file.

With the modular refactoring, we found some hidden bugs that caused by static/global variables. This refactoring tries to get rid of static/global variables to promote the reentrancy.

Please see each commit for a more structured view.

cc @fitzthum @ChengyuZhu6

@Xynnn007 Xynnn007 force-pushed the refact-config branch 8 times, most recently from db80b82 to c757c51 Compare September 11, 2024 03:40
@Xynnn007 Xynnn007 marked this pull request as ready for review September 11, 2024 04:15
@Xynnn007 Xynnn007 requested a review from a team as a code owner September 11, 2024 04:15
Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

A big improvement imo. I left a few comments.

image-rs/src/image.rs Outdated Show resolved Hide resolved
image-rs/src/signature/mod.rs Outdated Show resolved Hide resolved
image-rs/src/signature/mod.rs Outdated Show resolved Hide resolved
image-rs/src/signature/mod.rs Outdated Show resolved Hide resolved
image-rs/src/builder.rs Outdated Show resolved Hide resolved
image-rs/src/builder.rs Outdated Show resolved Hide resolved
image-rs/src/resource/kbs/mod.rs Outdated Show resolved Hide resolved
image-rs/src/signature/policy/mod.rs Show resolved Hide resolved
@Xynnn007 Xynnn007 force-pushed the refact-config branch 2 times, most recently from 6e87742 to 8813e45 Compare September 13, 2024 08:26
Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM

I think there are still some improvements to make in image-rs, but this is a step forward.

Copy link
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

Thanks for the work @Xynnn007. Just a comment:

// lint from warning dead code.
common::clean_configs()
.await
.expect("Delete configs failed.");
let mut image_client = image_rs::image::ImageClient::new(work_dir.path().to_path_buf());
Copy link
Member

Choose a reason for hiding this comment

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

@Xynnn007 Do we need to initialize the image_client instance using ClientBuilder ?

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

btw The ClientBuilder logic brings image policy, auth file, sigstore config fetching in the time of creation of ClientBuilder.build(), and supports to read them from local filesystem.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. You mean that ClientBuilder.build() would read some configs by default that are irrelevant to image descryption?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. I mean that image policy, auth file, sigstore config all are explicitly set in the config file. If any/all of them is set, the read will be performed by ClientBuilder.build()

@Xynnn007
Copy link
Member Author

I think there are still some improvements to make in image-rs, but this is a step forward.

Yes. Please give some ideas about this, and I will try to figure out if we can promote in this pr together

Refactor signature module from function way to object oriented. Also
changed the logic a little to avoid duplicated get resource operation.

Signed-off-by: Xynnn007 <[email protected]>
change the whole resource module's API into an object. This would help
to make the modularation clear and better maintainance.

Also, change the feature `getresource` to `kbs`. Because this feature
only adds supports to find resources with `kbs:///` uri scheme.

deletes useless lines in Cargo.toml

Signed-off-by: Xynnn007 <[email protected]>
Now auth is a separate module with an object. This would help to
maintain the internal status of each auth module.

Signed-off-by: Xynnn007 <[email protected]>
With clientBuilder, we can get registry auth, sigstore config file and
image policy when the client is built.

This would help to avoid duplicated file getting.

Also, combined CDH's image config with image-rs'.
To leverage the new client builder, we mark the image pull object as a
static one to be lazily initialized. Because before CDH is set up, the
initialization steps of image client cannot pass when fetching resources
from KBS.

Signed-off-by: Xynnn007 <[email protected]>
Now we use kbs to refer to the old feature getresource

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

Rebased to resolve the conflicts.

Copy link
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the work @Xynnn007. BTW, I have a question that’s unrelated to this PR:
I’ve noticed that some comments in the code of the repo use three slashes ///, while others use two //. Are there specific scenarios for using these two types of comments? For example, is it recommended to use /// in one comment type and // in another comment type?

// lint from warning dead code.
common::clean_configs()
.await
.expect("Delete configs failed.");
let mut image_client = image_rs::image::ImageClient::new(work_dir.path().to_path_buf());
Copy link
Member

Choose a reason for hiding this comment

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

Got it. You mean that ClientBuilder.build() would read some configs by default that are irrelevant to image descryption?

@fitzthum
Copy link
Member

I've noticed that some comments in the code of the repo use three slashes ///, while others use two //. Are there specific scenarios for using these two types of comments? For example, is it recommended to use /// in one comment type and // in another comment type?

Three slash comments get used to generate the rustdocs. You can also use /** */ to do block doc comments. Ideally we should have one of these comments at the top of all our public functions in components that can be used as crates.

@ChengyuZhu6
Copy link
Member

I've noticed that some comments in the code of the repo use three slashes ///, while others use two //. Are there specific scenarios for using these two types of comments? For example, is it recommended to use /// in one comment type and // in another comment type?

Three slash comments get used to generate the rustdocs. You can also use /** */ to do block doc comments. Ideally we should have one of these comments at the top of all our public functions in components that can be used as crates.

Thanks Tobin. I noticed that some public structures or variables in the structure in the code are commented with //, while others are commented with ///. This seems curious to me.

@ChengyuZhu6
Copy link
Member

BTW, do we need to cut a minor release and bump guest-components and image-rs to the new minor release in kata, according to the community meeting? If so, I recommend holding off on merging this PR until the release is cut.

@fitzthum
Copy link
Member

BTW, do we need to cut a minor release and bump guest-components and image-rs to the new minor release in kata, according to the community meeting? If so, I recommend holding off on merging this PR until the release is cut.

It sounds like we don't need another release, but we still might want to wait until next week to merge this stuff just in case.

@fitzthum
Copy link
Member

I noticed that some public structures or variables in the structure in the code are commented with //, while others are commented with ///. This seems curious to me.

Yeah I think we have not been very consistent so far.

@Xynnn007
Copy link
Member Author

Xynnn007 commented Oct 9, 2024

Added another commit to replace HTTPS_PROXY and NO_PROXY env setting with config to oci-client.

New dependency oci-client version supports to set HTTPS_PROXY and
NO_PROXY without setting env of the whole process.

Also, this commit marks the cosign module's client TODO to add a proxy
configuration.

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

Added another commit to support self-signed image registry certs in CDH/image-rs config.

Seeing that cosign will also need to fetch signatures from the same registry, I made a PR to support this in sigstore-rs crate. sigstore/sigstore-rs#392

After that PR is merged we can make the story complete

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