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/podman rootless #2370

Merged
merged 12 commits into from
Oct 5, 2023
Merged

Feat/podman rootless #2370

merged 12 commits into from
Oct 5, 2023

Conversation

YJDoc2
Copy link
Collaborator

@YJDoc2 YJDoc2 commented Sep 19, 2023

Ref : #2208 , #719 , #1171

This switches from dbus-rs to natively implemented dbus connection implementation, in order to make rootless invocation with podman work. This is almost done but still few final touches are remaining, so marked as WIP.

This PR can be split into 4 parts :

Apologies for such large PR, but to validate that the code works, I have to completely switch over to dbus_native, and test. If required, I can split the PR into multiple ones according to above splits, but then the individual PRs may not be testable.

There are several places where I'm not particularly happy with my implementation, so any and all comments, suggestions and feedback is welcome to improve this!

Thank you :)

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2023

Codecov Report

Merging #2370 (263e6b8) into main (4b04abd) will increase coverage by 1.16%.
Report is 71 commits behind head on main.
The diff coverage is 72.27%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2370      +/-   ##
==========================================
+ Coverage   64.83%   65.99%   +1.16%     
==========================================
  Files         129      133       +4     
  Lines       15201    16814    +1613     
==========================================
+ Hits         9855    11096    +1241     
- Misses       5346     5718     +372     

@YJDoc2 YJDoc2 force-pushed the feat/podman-rootless branch from 9a31896 to a650514 Compare September 21, 2023 08:57
Comment on lines +54 to +68
let cpu_mask: Vec<_> = to_bitmask(cpus)
.map_err(SystemdCpuSetError::CpusBitmask)?
.into_iter()
.map(|v| v as u64)
.collect();
properties.insert(ALLOWED_CPUS, Variant::ArrayU64(cpu_mask));
}

if let Some(mems) = cpu.mems() {
let mems_mask = to_bitmask(mems).map_err(SystemdCpuSetError::MemoryNodesBitmask)?;
properties.insert(ALLOWED_NODES, Box::new(mems_mask));
let mems_mask: Vec<_> = to_bitmask(mems)
.map_err(SystemdCpuSetError::MemoryNodesBitmask)?
.into_iter()
.map(|v| v as u64)
.collect();
properties.insert(ALLOWED_NODES, Variant::ArrayU64(mems_mask));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In tests as well as other uses, the original code expected u64, so changed this to type u64 as well, instead of casting there

/// socket fd
socket: i32,
/// name id assigned by dbus for the connection
id: Option<String>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is not necessary to send ID, but I have added it as sending it is a better practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unit tests in this test the combined functionality of message serialization and individual type serialization. The "original" message in all tests are taken from zbus calls, so we know that those are valid messages.

@YJDoc2 YJDoc2 marked this pull request as ready for review September 22, 2023 09:44
@YJDoc2 YJDoc2 requested review from utam0k and a team September 22, 2023 09:45
@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Sep 22, 2023

With these changes, the failing tests in podman rootless are 136, 4 more that current main (132). I'll check and fix them in a separate PR, this only fixes the running with podman issues.
The binary size is also slightly large, but not much, which I think is acceptable.

The primary test for validating is the following command should run with and without root permissions, both

podman create --runtime $PWD/youki --name test hello-world
podman start -ia test # this should print the hello world message on terminal
podman rm test

podman run -it fedora /bin/bash # verify you can run commands inside the container

Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

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

Awesome.
Especially, I think it is good to have a good unit tests Why not divert some unit tests and add doc test?

docs/src/user/basic_setup.md Show resolved Hide resolved
docs/src/user/dbus-native.md Outdated Show resolved Hide resolved
@@ -42,7 +42,7 @@ jobs:
go-version: '1.20'
cache: true
- run: sudo apt-get -y update
- run: sudo apt-get install -y pkg-config libsystemd-dev libdbus-glib-1-dev libelf-dev libseccomp-dev btrfs-progs libbtrfs-dev
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hooray!

@yihuaf
Copy link
Collaborator

yihuaf commented Sep 24, 2023

This is technically a breaking change. I would include this change in a minor version bump.

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Sep 25, 2023

This is technically a breaking change. I would include this change in a minor version bump.

Yes, I will be adding a migration guide for this as @utam0k has suggested, just haven't bumped the version in this PR, as we usually do that in the release PRs when we do a new release.

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Sep 25, 2023

Especially, I think it is good to have a good unit tests Why not divert some unit tests and add doc test?

@utam0k , I'm not sure what you mean by this? Do you want me to change some of the current unit tests that I have added to doc tests instead, or do you want to keep unit tests as they are, and add more tests as doc tests?

@utam0k
Copy link
Member

utam0k commented Sep 25, 2023

Especially, I think it is good to have a good unit tests Why not divert some unit tests and add doc test?

@utam0k , I'm not sure what you mean by this? Do you want me to change some of the current unit tests that I have added to doc tests instead, or do you want to keep unit tests as they are, and add more tests as doc tests?

May I ask you to use documentation tests in simple util functions? For example:
https://github.com/containers/youki/pull/2370/files#diff-9347c2507177cda90306312df09422eccd4d3a259bc837ecb73a78c963a5c0f5R81

@YJDoc2 YJDoc2 force-pushed the feat/podman-rootless branch from b579273 to 998a715 Compare October 5, 2023 06:19
@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Oct 5, 2023

Hey @utam0k apologies for the delay. I have updated the migration guide and docs as you commented.
I tried converting some utils tests to doctests, but as the dbus_native module is private, they cannot be imported in the doctest.

When compiling a crate for use in doctests (with --test option), rustdoc will set #[cfg(doctest)]. Note that they will still link against only the public items of your crate; if you need to test private items, you need to write a unit test.

https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#include-items-only-when-collecting-doctests

So for now I have kept the unit tests as they were.
Please take a look : )

@YJDoc2 YJDoc2 force-pushed the feat/podman-rootless branch from 998a715 to 263e6b8 Compare October 5, 2023 06:29
@YJDoc2 YJDoc2 requested a review from utam0k October 5, 2023 07:25
Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

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

May I ask you to add e2e test for rootless podmain in another PR if possible?

@utam0k utam0k merged commit cc39179 into youki-dev:main Oct 5, 2023
@utam0k
Copy link
Member

utam0k commented Oct 5, 2023

@orimanabu May I ask you to give it a try?

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Oct 5, 2023

May I ask you to add e2e test for rootless podmain in another PR if possible?

Yes, I'll do that 👍

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