3879 Commits

Author SHA1 Message Date
Julio Montes
98cc979ae1 agent/rustjail: remove makedev function
remove `makedev` function, use `nix`'s implementation instead

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
b99fefad7e agent/rustjail: add unit tests for ms_move_rootfs and mask_path
Increase code coverage of mount.rs

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
d79fad2dd8 agent/rustjail: implement functions to chroot
Use conditional compilation (#[cfg]) to change chroot behaviour
at compilation time. For example, such function will just return
`Ok(())` when the unit tests are being compiled, otherwise real
chroot operation is performed.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
25c91afbea agent/rustjail: add unit test for pivot_rootfs
Add unit test for pivot_rootfs increasing the code coverage of
mount.rs

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
7cf0fd95f1 agent/rustjail: implement functions to pivot_root
Use conditional compilation (#[cfg]) to change pivot_root behaviour
at compilation time. For example, such function will just return
`Ok(())` when the unit tests are being compiled, otherwise real
pivot_root operation is performed.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
672da4d08c agent/rustjail: add unit test for mount_cgroups
Add a unit test for `mount_cgroups` increasing the code coverage
of mount.rs from 44% to 52%

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
ab61cf7f9f agent/rustjail: add unit test for init_rootfs
Add a unit test for `init_rootfs` increasing the code coverage
of mount.rs from 0% to 44%.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
0a0714c9c3 agent/rustjail/mount: don't use unwrap
Don't use unwrap in `init_rootfs` instead return an Error, this way
we can write unit tests that don't panic.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
3dc9452bc6 agent/rustjail: add tempfile crate as depedency
Add tempfile crate as depedency, it will be used in the following
commits to create temporary directories for unit testing.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Julio Montes
d756f52c73 rustjail: implement functions to mount and umount files
Use conditional compilation (#[cfg]) to change mount and umount
behaviours at compilation time. For example, such functions will just
return `Ok(())` when the unit tests are being compiled, otherwise real
mount and umount operations are performed.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-21 15:24:53 -05:00
Peng Tao
b518ddeac8 agent: fix agent panic running as init
We should mount procfs before trying to parse kernel command lines.

Fixes: #771
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-09-21 20:58:13 +08:00
James O. D. Hunt
1a77f69e15 runtime: make kata-check check for newer release
Update `kata-check` to see if there is a newer version available for
download. Useful for users installing static packages (without a package
manager).

Fixes: #734.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-09-21 13:47:29 +01:00
Ychau Wang
1839dfd95a runtime: Clear the VCMock 1.x API Methods from 2.0
Clear the 1.x branch api methods in the 2.0. Keep the same methods to
the VC interface, like the VCImpl struct.

Fixes: #751

Signed-off-by: Ychau Wang <wangyongchao.bj@inspur.com>
2020-09-18 16:30:12 +08:00
Peng Tao
7e33e36f4a Merge pull request #698 from liubin/feature/146-add-cgroup-v2-for-agent
agent: add cgroup v2 support
2020-09-18 14:45:38 +08:00
Peng Tao
922a55e4fe Merge pull request #737 from cailca/736
runtime: Don't use hard-coded crio config
2020-09-18 14:23:14 +08:00
Christophe de Dinechin
615ffb93e5 agent: Generate version file with more adequate information in it.
The version.rs file is now generated to contain up-to-date information
from the makefile, including git commit and the full binary path.

The makefile has also been modified to make it easier to add changes
in generated files based on makefile variables.

Fixes: #740

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
2020-09-17 16:41:00 +02:00
James O. D. Hunt
f13ca94e10 agent: Fix setting of version
Fix the bug where the version string generated by the `Makefile` was not
being passed to the agent, resulting in a "unknown" version.

Fixes: #725.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-09-17 16:41:00 +02:00
James O. D. Hunt
c823b4cd99 agent: Make build remove generated files on clean
Ensure that `make clean` removes generated files.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-09-17 16:41:00 +02:00
Peng Tao
22876b2da6 agent: allow multiple wait on the same process
Until a container is deleted, agent should allow runtime to wait for
a process in parallel, as being supported by the go agent.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-09-16 21:15:51 +08:00
Qian Cai
295f5100a3 runtime: Don't use hard-coded crio config
In show_container_mgr_details(), it used "cat /etc/crio/crio.conf"
instead of "crio config".

Fixes: #736
Signed-off-by: Qian Cai <cai@redhat.com>
2020-09-16 08:38:54 -04:00
Peng Tao
6487044fa1 shimv2: trust cached status when deleting containers
vc status might not be accurate because it does not watch container
status change.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-09-16 16:47:56 +08:00
Peng Tao
325a4f868d shimv2: do not kill a stopped exec process
Same as containers, it is possible for an exec process to stop so
quickly that containerd may send a parallel Kill request. We should
just return success in such case.

Fixes: #716
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-09-16 16:47:46 +08:00
bin liu
d7c77b69dc runtime: write oom file to notify CRI-O tha OOM occurred
CRI-O is not use event like containerd, it's depending on
file name `oom` to dectect if an OOM occurred.

Signed-off-by: bin liu <bin@hyper.sh>
2020-09-16 10:35:28 +08:00
Qian Cai
7225460a68 shimv2: add a comment in checkAndMount()
In checkAndMount(), it is not clear why we check IsBlockDevice() and if
DisableBlockDeviceUse == false and then only return "false, nil" instead
of "false, err". Adding a comment to make it a bit more readable.

Fixes: #732
Signed-off-by: Qian Cai <cai@redhat.com>
2020-09-15 13:01:03 -04:00
bin liu
15065e4472 agent: add cgroup v2 support
This PR add basic cgroup v2 support for agent.

Fixes: #146, #357

Signed-off-by: bin liu <bin@hyper.sh>
2020-09-15 10:38:55 +08:00
zhanghj
2ce97ec680 virtiofsd: fix typo in test code
fix typo in virtiofsd_test.go

Fixes: #712

Signed-off-by: zhanghj <zhanghj.lc@inspur.com>
2020-09-14 05:35:10 -04:00
Peng Tao
6e328c0599 Merge pull request #704 from liubin/feature/689-setup-guest-DNS
agent: setup DNS for guest
2020-09-14 09:51:45 +08:00
bin liu
6520320fc6 agent: setup DNS for guest
This PR is a porting of
https://github.com/kata-containers/agent/pull/625

Fixes: #689

Signed-off-by: bin liu <bin@hyper.sh>
2020-09-13 21:43:07 +08:00
Peng Tao
37e3f89424 Merge pull request #709 from liubin/tmp/debug-travis-sudo
ci: run agent test under root user
2020-09-12 12:47:06 +08:00
bin liu
90e0dc8809 ci: run agent test under root user
Running agent test now only support normal user,
under root user also needed.

Fixes: #708

Signed-off-by: bin liu <bin@hyper.sh>
2020-09-11 22:42:13 +08:00
Peng Tao
e3ea8544f4 Merge pull request #694 from lifupan/2.0-dev
rustjail: fix the issue of invalid cgroup_parent path
2020-09-11 10:28:33 +08:00
fupan.lfp
c133a4561d rustjail: fix the issue of invalid cgroup_parent path
The cgroup_parent path is expected to be absolute path,
add an '/' prefix to the passed cgroup_parent path to make
sure it's an absolute path.

Fixes: #336

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-09-10 11:12:56 +08:00
bin liu
d86e74674c agent: add retry between doing CPU hotplug and make it online.
Sometimes runtime will fail in onlining CPU process,
because when the runtime calls to QMP
`device_add`, QEMU doesn't allocate all vCPUs inmediatelly.

Fixes: #665

Signed-off-by: bin liu <bin@hyper.sh>
2020-09-10 07:36:18 +08:00
James O. D. Hunt
1a734bbb79 Merge pull request #668 from cmaf/unit-virtcontainers-utils-compare
virtcontainers: Add unit test for utils/compare.go
2020-09-08 11:35:28 +01:00
Julio Montes
b30dc26986 Merge pull request #642 from devimc/2020-08-13/agent/anyhow
reimplement error handling: use anyhow
2020-09-07 10:13:21 -05:00
Chelsea Mafrica
fd3ce81518 Merge pull request #672 from c3d/200903-spelling
trivial: Fix spelling of "privilege"
2020-09-04 12:58:18 -07:00
Julio Montes
0be02a8fd3 runtime: qemu: reduce boot time and memory footprint
The linux kernel feature RANDOMIZE_BASE improved the security and at
the same time increased the memory footprint of a kata container,
this feature was enabled in kata-containers/packaging#1006.
In order to mitigate this increase in memory consumption, we can
boot container using the uncompressed kernel.

Reduce boot time by ~5%
Reduce KSM memory footprint by ~14%
Reduce noKSM memory footprint by ~27%

fixes #669

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 10:25:09 -05:00
Julio Montes
8b07bc2c80 agent: fix unit tests - remove rustjail::errors
Fix unit tests and use `anyhow::Error`.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:29:12 -05:00
Julio Montes
6c96d66667 agent: update Cargo toml and lock
`rustjail::erros` was removed in a previous commit, hence some external crates
like `error_chain` are no longger required, update Cargo.toml and Cargo.lock
to reflect these changes.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:29:12 -05:00
Julio Montes
46d7b9b8dc agent/rustjail: remove rustjail::errors
`anyhow` replaces `rustjail::errors`, hence it's not longer needed

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:28:50 -05:00
Julio Montes
fbb79739c9 agent: Use anyhow for error handling
Don't use `rustjail::errors` for error handling, since it's not
thread safe and there are better alternatives like `anyhow`.

`anyhow` attaches context to help the person troubleshooting
the error understand where things went wrong, for example:

Current error messages:

```
No such file or directory (os error 2)
```

With `anyhow`:

```
Error: Failed to read config.json
Caused by:
    No such file or directory (os error 2)
```

fixes #641

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:23:17 -05:00
Julio Montes
33759af548 agent: Add anyhow dependency
anyhow provides `anyhow::Error`, a trait object based error type for
easy idiomatic error handling in Rust applications

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:22:13 -05:00
Julio Montes
c192446a59 agent/rustjail: Use anyhow for error handling
Convert all Errors and Results to `anyhow::Error` and `anyhow::Result`
respectively

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:22:13 -05:00
Julio Montes
2e3e2ce114 agent/rustjail/capabilities: Use anyhow for error handling
Use `.to_string` to wrap up `caps::errors::Error`s since they are not
thread safe, otherwise `cargo build` will fail with the following error:

```
doesn't satisfy `caps::errors::Error: std::marker::Sync`
```

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:22:13 -05:00
Julio Montes
6a4c9b14f2 agent/rustjail/cgroups: Use anyhow for error handling
Return `anyhow::Result` from all the functions in this directory.
Add function `io_error_kind_eq` to compare an `anyhow::Error` with an
`io::Error`, this function downcast the `anyhow::Error`.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:22:13 -05:00
Julio Montes
359286a87d agent/rustjail: Add anyhow dependency
anyhow provides `anyhow::Error`, a trait object based error type for
easy idiomatic error handling in Rust applications.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-09-04 08:22:13 -05:00
Christophe de Dinechin
dd60e56f28 trivial: Fix spelling of "privilege"
I noticed the spelling mistake while reviewing another change and
doing a "grep" for "privilege" that turned up nothing.

Fixes: #671

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
2020-09-04 11:31:09 +02:00
Christophe de Dinechin
6e54767344 Merge pull request #663 from dgibson/machinne
runtime: Fix typo in hotplugVFIODevice()
2020-09-04 09:58:34 +02:00
David Gibson
cb9993759b runtime: Fix typo in hotplugVFIODevice()
"machineType" is misspelled as "machinneType".

Fixes: #670

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-09-04 14:28:51 +10:00
Chelsea Mafrica
0d198f930e virtcontainers: Add unit test for utils/compare.go
Add unit test for virtcontainers/utils/compare.go to increase overall
coverage.

Fixes #661

Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
2020-09-03 13:38:43 -07:00