Commit Graph

875 Commits

Author SHA1 Message Date
Manabu Sugimoto
2c218a07b9 agent: Modify Kata agent for runk
Generate an oci-kata-agent which is a customized agent to be
called from runk which is a Rust-based standard OCI container
runtime based on Kata agent.

Fixes: #2784

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2022-04-28 00:48:57 +09:00
James O. D. Hunt
0a6e7d443e Merge pull request #3910 from etrunko/agent_random
Agent: Unit tests for random.rs
2022-04-27 09:41:02 +01:00
Garrett Mahin
4b9e78b837 rustjail: Add tests for mount_grpc_to_oci
Add test coverage for mount_grpc_to_oci in rustjail/src/lib.rs

Fixes: #4106

Signed-off-by: Garrett Mahin <garrett.mahin@gmail.com>
2022-04-25 08:37:17 -05:00
James O. D. Hunt
bc919cc54c Merge pull request #4122 from bradenrayhorn/test-mount-from
rustjail: add tests for mount_from function
2022-04-25 11:55:21 +01:00
James O. D. Hunt
cb8dd0f4fc Merge pull request #4143 from garrettmahin/test-hooks-grpc-to-oci
rustjail: Add tests for hooks_grpc_to_oci
2022-04-25 10:50:52 +01:00
Braden Rayhorn
81f6b48626 agent: add tests for create_logger_task function
Add tests for create_logger_task function in src/main.rs.

Fixes: #4113

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-24 21:38:32 -05:00
Garrett Mahin
96bc3ec2e9 rustjail: Add tests for hooks_grpc_to_oci
Add test coverage for hooks_grpc_to_oci in rustjail/src/lib.rs

Fixes: #4142

Signed-off-by: Garrett Mahin <garrett.mahin@gmail.com>
2022-04-22 19:20:04 -05:00
holyfei
0239502781 agent: modify the type of swappiness to u64
The type of MemorySwappiness in runtime is uint64, and the type of swappiness in agent is int64,
if we set max uint64 in runtime and pass it to agent, the value will be equal to -1. We should
modify the type of swappiness to u64

Fixes: #4123

Signed-off-by: holyfei <yangfeiyu20092010@163.com>
2022-04-22 16:55:37 +08:00
Braden Rayhorn
f385b21b05 rustjail: add tests for mount_from function
Add tests for the mount_from function in rustjail mount.rs file.

Fixes: #4121

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-20 20:04:57 -05:00
Braden Rayhorn
0e7f1a5e3a agent: move assert_result macro to test_utils file
Move the assert_result macro to the shared test_utils file
so that it is not duplicated in individual files.

Fixes: #4093

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-19 18:57:16 -05:00
Fabiano Fidêncio
604a795073 Merge pull request #4096 from garrettmahin/test-root-grpc-to-oci
rustjail: Add tests for root_grpc_to_oci
2022-04-19 21:38:58 +02:00
Fabiano Fidêncio
f619c65b6a Merge pull request #4074 from bradenrayhorn/test-mount-to-rootfs
agent: add tests for mount_to_rootfs function
2022-04-19 21:36:11 +02:00
Fabiano Fidêncio
7ec42951f2 Merge pull request #4035 from bradenrayhorn/test-update-container-namespaces
agent: add tests for update_container_namespaces
2022-04-19 21:36:02 +02:00
Fabiano Fidêncio
e6bc912439 Merge pull request #3940 from bradenrayhorn/test-is-signal-handled
agent: add tests for is_signal_handled function
2022-04-19 21:35:48 +02:00
Fabiano Fidêncio
dbb0c67523 Merge pull request #4072 from fengwang666/dv-bug
agent: best-effort removing mount point
2022-04-19 10:08:40 +02:00
Bin Liu
b19bfac7cd Merge pull request #4042 from yibozhuang/direct-assign-fsgroup
fsGroup support for direct-assigned volume
2022-04-16 10:23:15 +08:00
Garrett Mahin
2256bcb6ab rustjail: Add tests for root_grpc_to_oci
Add test coverage for root_grpc_to_oci in rustjail/src/lib.rs

Fixes: #4095

Signed-off-by: Garrett Mahin <garrett.mahin@gmail.com>
2022-04-15 11:09:18 -05:00
Feng Wang
aabcebbf58 agent: best-effort removing mount point
During container exit, the agent tries to remove all the mount point directories,
which can fail if it's a readonly filesytem (e.g. device mapper). This commit ignores
the removal failure and logs a warning message.

Fixes: #4043

Signed-off-by: Feng Wang <feng.wang@databricks.com>
2022-04-13 22:40:23 -07:00
Fabiano Fidêncio
78f30c33c6 agent: Avoid agent panic when reading empty stats
This was seen in an issue report, where we'd try to unwrap a None value,
leading to a panic.

Fixes: #4077
Related: #4043

Full backtrace:
```
"thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', rustjail/src/cgroups/fs/mod.rs:593:31"
"stack backtrace:"
"   0:     0x7f0390edcc3a - std::backtrace_rs::backtrace::libunwind::trace::hd5eff4de16dbdd15"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5"
"   1:     0x7f0390edcc3a - std::backtrace_rs::backtrace::trace_unsynchronized::h04a775b4c6ab90d6"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5"
"   2:     0x7f0390edcc3a - std::sys_common::backtrace::_print_fmt::h3253c3db9f17d826"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys_common/backtrace.rs:67:5"
"   3:     0x7f0390edcc3a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h02bfc712fc868664"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys_common/backtrace.rs:46:22"
"   4:     0x7f0390a91fbc - core::fmt::write::hfd5090d1132106d8"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/fmt/mod.rs:1149:17"
"   5:     0x7f0390edb804 - std::io::Write::write_fmt::h34acb699c6d6f5a9"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/io/mod.rs:1697:15"
"   6:     0x7f0390edbee0 - std::sys_common::backtrace::_print::hfca761479e3d91ed"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys_common/backtrace.rs:49:5"
"   7:     0x7f0390edbee0 - std::sys_common::backtrace::print::hf666af0b87d2b5ba"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys_common/backtrace.rs:36:9"
"   8:     0x7f0390edbee0 - std::panicking::default_hook::{{closure}}::hb4617bd1d4a09097"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:211:50"
"   9:     0x7f0390edb2da - std::panicking::default_hook::h84f684d9eff1eede"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:228:9"
"  10:     0x7f0390edb2da - std::panicking::rust_panic_with_hook::h8e784f5c39f46346"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:606:17"
"  11:     0x7f0390f0c416 - std::panicking::begin_panic_handler::{{closure}}::hef496869aa926670"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:500:13"
"  12:     0x7f0390f0c3b6 - std::sys_common::backtrace::__rust_end_short_backtrace::h8e9b039b8ed3e70f"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys_common/backtrace.rs:139:18"
"  13:     0x7f0390f0c372 - rust_begin_unwind"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5"
"  14:     0x7f03909062c0 - core::panicking::panic_fmt::h568976b83a33ae59"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14"
"  15:     0x7f039090641c - core::panicking::panic::he2e71cfa6548cc2c"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:48:5"
"  16:     0x7f0390eb443f - <rustjail::cgroups::fs::Manager as rustjail::cgroups::Manager>::get_stats::h85031fc1c59c53d9"
"  17:     0x7f03909c0138 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hfa6e6cd7516f8d11"
"  18:     0x7f0390d697e5 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hffbaa534cfa97d44"
"  19:     0x7f039099c0b3 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hae3ab083a06d0b4b"
"  20:     0x7f0390af9e1e - std::panic::catch_unwind::h1fdd25c8ebba32e1"
"  21:     0x7f0390b7c4e6 - tokio::runtime::task::raw::poll::hd3ebbd0717dac808"
"  22:     0x7f0390f49f3f - tokio::runtime::thread_pool::worker::Context::run_task::hfdd63cd1e0b17abf"
"  23:     0x7f0390f3a599 - tokio::runtime::task::raw::poll::h62954f6369b1d210"
"  24:     0x7f0390f37863 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1c58f232c078bfe9"
"  25:     0x7f0390f4f3dd - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2d329a84c0feed57"
"  26:     0x7f0390f0e535 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h137e5243c6233a3b"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/alloc/src/boxed.rs:1694:9"
"  27:     0x7f0390f0e535 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7331c46863d912b7"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/alloc/src/boxed.rs:1694:9"
"  28:     0x7f0390f0e535 - std::sys::unix:🧵:Thread:🆕:thread_start::h1fb20b966cb927ab"
"                               at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/sys/unix/thread.rs:106:17"
```

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
2022-04-12 11:19:08 +02:00
Braden Rayhorn
9b6f24b2ee agent: add tests for mount_to_rootfs function
Add test coverage for mount_to_rootfs function in src/mount.rs.
Includes minor refactoring to make function more easily testable.

Fixes #4073

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-11 21:42:38 -05:00
Braden Rayhorn
c3776b1792 agent: add tests for is_signal_handled function
Add test coverage for is_signal_handled function in rpc.rs. Includes
refactors to make the function testable and handle additional cases.

Fixes #3939

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-11 21:23:55 -05:00
Braden Rayhorn
9c22d9554e agent: add tests for update_container_namespaces
Add test coverage for update_container_namespaces function
in src/rpc.rs. Includes minor refactor to make function easier
to test.

Fixes #4034

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-11 18:27:30 -05:00
Yibo Zhuang
92c00c7e84 agent: fsGroup support for direct-assigned volume
Adding two functions set_ownership and
recursive_ownership_change to support changing group id
ownership for a mounted volume.

The set_ownership will be called in common_storage_handler
after mount_storage performs the mount for the volume.
set_ownership will be a noop if the FSGroup field in the
Storage struct is not set which indicates no chown will be
performed. If FSGroup field is specified, then it will
perform the recursive walk of the mounted volume path to
change ownership of all files and directories to the
desired group id. It will also configure the SetGid bit
so that files created the directory will have group
following parent directory group.

If the fsGroupChangePolicy is on root mismatch,
then the group ownership will be skipped if the root
directory group id alreasy matches the desired group
id and if the SetGid bit is also set on the root directory.

This is the same behavior as what
Kubelet does today when performing the recursive walk
to change ownership.

Fixes #4018

Signed-off-by: Yibo Zhuang <yibzhuang@gmail.com>
2022-04-11 08:57:13 -07:00
Braden Rayhorn
9d5e7ee0d4 agent: add tests for mount_storage
Add test coverage for mount_storage function in src/mount.rs.

Fixes: #4068

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-10 21:42:20 -05:00
Fabiano Fidêncio
698e45f403 Merge pull request #4057 from bradenrayhorn/test-parse-mount-flags-and-options
agent: add test coverage for parse_mount_flags_and_options function
2022-04-08 14:42:18 +02:00
Fabiano Fidêncio
761e8313de Merge pull request #3985 from bradenrayhorn/test-do-write-stream
agent: add tests for do_write_stream function
2022-04-08 14:34:57 +02:00
Peng Tao
a83a16e32c Merge pull request #4059 from garrettmahin/test-process-grpc-to-oci
rustjail: add test coverage for process_grpc_to_oci function
2022-04-08 15:39:28 +08:00
garrettmahin
c31cd0e81a rustjail: add test coverage for process_grpc_to_oci function
Add test coverage for the process_grpc_to_oci function in src/rustjail/lib.rs

Fixes #4058

Signed-off-by: Garrett Mahin <garrett.mahin@gmail.com>
2022-04-07 20:50:48 -05:00
Braden Rayhorn
1118a3d2da agent: add test coverage for parse_mount_flags_and_options function
Add test coverage for the parse_mount_flags_and_options function
in src/mount.rs.

Fixes #4056

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-07 17:46:35 -05:00
Manabu Sugimoto
eff7c7e0ff agent: Allow the agent to be rebuilt with the change of Cargo features
This allows the kata-agent to be rebuilt when Cargo "features" is
changed. The Makefile for the agent do not need to specify the
sources for prerequisites by having Cargo check for the sources
changes.

Fixes: #4052

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2022-04-07 20:09:20 +09:00
Braden Rayhorn
485aeabb6b agent: add tests for do_write_stream function
Add test coverage for do_write_stream function of AgentService
in src/rpc.rs. Includes minor refactoring to make function more
easily testable.

Fixes #3984

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-04-04 08:21:01 -05:00
Bin Liu
416cc90b7a Merge pull request #3972 from wfly1998/main
agent: use ms as unit of cputime instead of ticks
2022-04-01 15:34:06 +08:00
Wang Xingxing
0d765bd082 agent: fix container stop error with signal SIGRTMIN+3
The nix::sys::signal::Signal package api cannot deal with SIGRTMIN+3,
directly use libc function to send the signal.

Fixes: #3990

Signed-off-by: Wang Xingxing <stellarwxx@163.com>
2022-03-31 10:49:45 +08:00
Yu Li
800e4a9cfb agent: use ms as unit of cputime instead of ticks
For the library `procfs`, the unit of values in `CpuTime` is ticks,
and we do not know how many ticks per second from metrics because the
`tps` in `CpuTime` is private.

But there are some implements in `CpuTime` for getting these values,
e.g., `user_ms()` for `user`, and `nice_ms()` for `nice`.  With these
values, accurate time can be obtained.

Fixes: #3979

Acked-by: zhaojizhuang <571130360@qq.com>
Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
2022-03-28 19:30:09 +08:00
Feng Wang
0928eb9f4e agent: Kill the all the container processes of the same cgroup
Otherwise the container process might leak and cause an unclean exit

Fixes: #3913

Signed-off-by: Feng Wang <feng.wang@databricks.com>
2022-03-27 10:06:58 -07:00
Dan Middleton
32131cb8ba Agent: fix unneeded late initialization lint
Clippy v1.58 added needless_late_init

Fixes #3933

Signed-off-by: Dan Middleton <dan.middleton@intel.com>
2022-03-22 10:17:24 -05:00
Eduardo Lima (Etrunko)
1cad3a4696 agent/random: Ensure data.len > 0
Also adds a test to cover this scenario

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2022-03-18 15:13:51 -03:00
Eduardo Lima (Etrunko)
33c953ace4 agent: Add test_ressed_rng_not_root
Same as previous test, but does not skip if it is not running as root.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2022-03-18 15:13:51 -03:00
Wainer dos Santos Moschetta
39a35b693a agent: Add test to random::reseed_rng()
Introduced an unit test for the random::reseed_rng() function.

Fixes #291
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
2022-03-18 10:23:22 -03:00
Eduardo Lima (Etrunko)
d8f39fb269 agent/random: Rename RNDRESEEDRNG to RNDRESEEDCRNG
Make this definition match the one in kernel:

5bfc75d92e/include/uapi/linux/random.h (L38-L39)

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2022-03-18 10:23:22 -03:00
Jack Hance
92ce5e2dc4 rustjail: optimization, merged several writelns into one
Optimized several writelns by merging them into one in src/utils.rs

Fixes: #3772

Signed-off-by: Jack Hance <jack.hance@ndsu.edu>
2022-03-11 13:18:58 -06:00
Fabiano Fidêncio
5a7fd943c1 Merge pull request #3838 from bradenrayhorn/get-memory-info-tests
agent: add tests for get_memory_info function
2022-03-09 23:21:20 +01:00
Braden Rayhorn
c088a3f3ad agent: add tests for get_memory_info function
Add test coverage for get_memory_info function in src/rpc.rs. Includes
some minor refactoring of the function.

Fixes #3837

Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
2022-03-09 11:34:35 -06:00
Julio Montes
293e61dc6e Merge pull request #3766 from dgibson/hugepages
Improve error checking of hugepage allocation
2022-03-08 10:21:57 -06:00
Bin Liu
deb8ce97a8 Merge pull request #3836 from liubin/fix/minor-fix
Enhancement: fix comments/logs and delete not used function
2022-03-07 17:26:30 +08:00
bin
b257e0e5ab rustjail: delete function signal in BaseContainer
Function signal in BaseContainer is not used anymore.

Fixes: #3835

Signed-off-by: bin <bin@hyper.sh>
2022-03-05 10:33:15 +08:00
bin
d647b28bb8 agent: delete meaningless FIXME comment
The test has passed, the FIX comment should
be deleted.

Fixes: #3835

Signed-off-by: bin <bin@hyper.sh>
2022-03-05 10:33:15 +08:00
Feng Wang
f905161bbb runtime: mount direct-assigned block device fs only once
Mount the direct-assigned block device fs only once and keep a refcount
in the guest. Also use the ro flag inside the options field to determine
whether the block device and filesystem should be mounted as ro

Fixes: #3454

Signed-off-by: Feng Wang <feng.wang@databricks.com>
2022-03-03 18:57:02 -08:00
shuochen0311
27fb490228 agent: add get volume stats handler in agent
retrieve the stats of direct-assigned volumes from the guest

Fixes: #3454

Signed-off-by: shuochen0311 <shuo.chen@databricks.com>
2022-03-03 18:57:02 -08:00
Feng Wang
4e00c2377c agent: add grpc interface for stat and resize operations
Add GetVolumeStats and ResizeVolume APIs for the runtime to query stat
and resize fs in the guest.

Fixes: #3454

Signed-off-by: Feng Wang <feng.wang@databricks.com>
2022-03-03 18:57:02 -08:00