Skip to content

Commit

Permalink
Kata-Containers: Fix kata-containers runtime (kubernetes-sigs#8068)
Browse files Browse the repository at this point in the history
* Kata-containes: Fix for ubuntu and centos sometimes kata containers fail to start because of access errors to /dev/vhost-vsock and /dev/vhost-net

* Kata-containers: use similar testing strategy as gvisor

* Kata-Containers: adjust values for 2.2.0 defaults

Make CI tests actually pass

* Kata-Containers: bump to 2.2.2 to fix sandbox_cgroup_only issue
  • Loading branch information
cristicalin authored and sakuraiyuta committed Apr 16, 2022
1 parent 1f0df94 commit 90f60e5
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
become: true
vars:
kata_containers_enabled: true
container_manager: containerd
roles:
- role: kubespray-defaults
- role: container-engine/containerd
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cniVersion": "0.2.0",
"name": "mynet",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "172.19.0.0/24",
"routes": [
{
"dst": "0.0.0.0/0"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"metadata": {
"name": "kata1"
},
"image": {
"image": "docker.io/library/hello-world:latest"
},
"log_path": "kata1.0.log",
"linux": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"metadata": {
"name": "kata1",
"namespace": "default",
"attempt": 1,
"uid": "hdishd83djaidwnduwk28bcsb"
},
"linux": {},
"log_directory": "/tmp"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
---
- name: Prepare
hosts: all
gather_facts: False
become: true
roles:
- role: kubespray-defaults
- role: bootstrap-os
- role: adduser
user: "{{ addusers.kube }}"
tasks:
- include_tasks: "../../../../download/tasks/download_file.yml"
vars:
download: "{{ download_defaults | combine(downloads.cni) }}"

- name: Prepare container runtime
hosts: all
become: true
vars:
container_manager: containerd
kube_network_plugin: cni
roles:
- role: kubespray-defaults
- role: network_plugin/cni
- role: container-engine/crictl
tasks:
- name: Copy test container files
copy:
src: "{{ item }}"
dest: "/tmp/{{ item }}"
owner: root
mode: 0644
with_items:
- container.json
- sandbox.json
- name: Create /etc/cni/net.d directory
file:
path: /etc/cni/net.d
state: directory
owner: kube
mode: 0755
- name: Setup CNI
copy:
src: "{{ item }}"
dest: "/etc/cni/net.d/{{ item }}"
owner: root
mode: 0644
with_items:
- 10-mynet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ def test_run(host):
assert "kata-runtime" in cmd.stdout


def test_run_pod(host):
image = "docker.io/library/hello-world:latest"
runtime = "io.containerd.kata-qemu.v2"

pull_command = "ctr image pull {}".format(image)
def test_run_check(host):
kataruntime = "/opt/kata/bin/kata-runtime"
with host.sudo():
cmd = host.command(pull_command)
cmd = host.command(kataruntime + " check")
assert cmd.rc == 0
assert "System is capable of running" in cmd.stdout

run_command = "ctr run --runtime {} {} kata1".format(runtime, image)

def test_run_pod(host):
runtime = "kata-qemu"

run_command = "/usr/local/bin/crictl run --with-pull --runtime {} /tmp/container.json /tmp/sandbox.json".format(runtime)
with host.sudo():
cmd = host.command(run_command)
assert cmd.rc == 0
assert "Hello from Docker!" in cmd.stdout

with host.sudo():
log_f = host.file("/tmp/kata1.0.log")

assert log_f.exists
assert b"Hello from Docker!" in log_f.content
16 changes: 16 additions & 0 deletions roles/container-engine/kata-containers/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@
mode: 0755
with_items:
- qemu

- name: kata-containers | Load vhost kernel modules
modprobe:
state: present
name: "{{ item }}"
with_items:
- vhost_vsock
- vhost_net

- name: kata-containers | Persist vhost kernel modules
copy:
dest: /etc/modules-load.d/kubespray-kata-containers.conf
mode: 0644
content: |
vhost_vsock
vhost_net
Loading

0 comments on commit 90f60e5

Please sign in to comment.