Merge pull request #382 from egernst/v2-containerd

kata-deploy: add support for v2 shim
This commit is contained in:
Sebastien Boeuf
2019-03-08 18:08:17 -08:00
committed by GitHub
2 changed files with 45 additions and 6 deletions

View File

@@ -41,6 +41,8 @@ spec:
mountPath: /var/run/dbus mountPath: /var/run/dbus
- name: systemd - name: systemd
mountPath: /run/systemd mountPath: /run/systemd
- name: local-bin
mountPath: /usr/local/bin/
volumes: volumes:
- name: crio-conf - name: crio-conf
hostPath: hostPath:
@@ -58,6 +60,9 @@ spec:
- name: systemd - name: systemd
hostPath: hostPath:
path: /run/systemd path: /run/systemd
- name: local-bin
hostPath:
path: /usr/local/bin/
updateStrategy: updateStrategy:
rollingUpdate: rollingUpdate:
maxUnavailable: 1 maxUnavailable: 1

View File

@@ -12,6 +12,10 @@ crio_conf_file="/etc/crio/crio.conf"
crio_conf_file_backup="${crio_conf_file}.bak" crio_conf_file_backup="${crio_conf_file}.bak"
containerd_conf_file="/etc/containerd/config.toml" containerd_conf_file="/etc/containerd/config.toml"
containerd_conf_file_backup="${containerd_conf_file}.bak" containerd_conf_file_backup="${containerd_conf_file}.bak"
shim_binary="containerd-shim-kata-v2"
shim_file="/usr/local/bin/${shim_binary}"
shim_backup="/usr/local/bin/${shim_binary}.bak"
# If we fail for any reason a message will be displayed # If we fail for any reason a message will be displayed
die() { die() {
msg="$*" msg="$*"
@@ -74,6 +78,7 @@ EOT
function configure_containerd() { function configure_containerd() {
# Configure containerd to use Kata: # Configure containerd to use Kata:
echo "Add Kata Containers as a supported runtime for containerd" echo "Add Kata Containers as a supported runtime for containerd"
mkdir -p /etc/containerd/ mkdir -p /etc/containerd/
if [ -f "$containerd_conf_file" ]; then if [ -f "$containerd_conf_file" ]; then
@@ -84,12 +89,33 @@ function configure_containerd() {
# https://github.com/kata-containers/packaging/issues/307 # https://github.com/kata-containers/packaging/issues/307
cat <<EOT | tee "$containerd_conf_file" cat <<EOT | tee "$containerd_conf_file"
[plugins] [plugins]
[plugins.cri.containerd] [plugins.cri]
[plugins.cri.containerd.untrusted_workload_runtime] [plugins.cri.containerd]
runtime_type = "io.containerd.runtime.v1.linux" [plugins.cri.containerd.runtimes.kata]
runtime_engine = "/opt/kata/bin/kata-runtime" runtime_type = "io.containerd.kata.v2"
runtime_root = ""
EOT EOT
#Currently containerd has an assumption on the location of the shimv2 implementation
#Until support is added (see https://github.com/containerd/containerd/issues/3073),
#create a link in /usr/local/bin/ to the v2-shim implementation in /opt/kata/bin.
if [ -f ${shim_file} ]; then
echo "warning: ${shim_binary} already exists" >&2
if [ ! -f ${shim_backup} ]; then
mv ${shim_file} ${shim_backup}
else
rm ${shim_file}
fi
fi
mkdir -p /usr/local/bin
cat << EOT | tee "$shim_file"
#!/bin/bash
KATA_CONF_FILE=/opt/kata/share/defaults/kata-containers/configuration.toml /opt/kata/bin/${shim_binary} \$@
EOT
chmod +x $shim_file
} }
function remove_artifacts() { function remove_artifacts() {
@@ -120,6 +146,13 @@ function cleanup_containerd() {
mv "$containerd_conf_file_backup" "$containerd_conf_file" mv "$containerd_conf_file_backup" "$containerd_conf_file"
fi fi
#Currently containerd has an assumption on the location of the shimv2 implementation
#Until support is added (see https://github.com/containerd/containerd/issues/3073), we manage
# a symlink to the v2-shim implementation
if [ -f "$shim_backup" ]; then
mv "$shim_backup" "$shim_file"
fi
} }
function reset_runtime() { function reset_runtime() {
@@ -157,11 +190,12 @@ function main() {
install_artifacts install_artifacts
configure_cri_runtime $runtime configure_cri_runtime $runtime
kubectl label node $NODE_NAME katacontainers.io/kata-runtime=true
;; ;;
cleanup) cleanup)
remove_artifacts
cleanup_cri_runtime $runtime cleanup_cri_runtime $runtime
kubectl label node $NODE_NAME --overwrite katacontainers.io/kata-runtime=cleanup kubectl label node $NODE_NAME --overwrite katacontainers.io/kata-runtime=cleanup
remove_artifacts
;; ;;
reset) reset)
reset_runtime $runtime reset_runtime $runtime