mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-09 12:49:12 +00:00
Merge pull request #8639 from fidencio/topic/kata-deploy-use-tomlq-to-configure-containerd
kata-deploy: Use `tomlq` to configure containerd
This commit is contained in:
@@ -10,6 +10,14 @@ ARG DESTINATION=/opt/kata-artifacts
|
|||||||
|
|
||||||
COPY ${KATA_ARTIFACTS} ${WORKDIR}
|
COPY ${KATA_ARTIFACTS} ${WORKDIR}
|
||||||
|
|
||||||
|
# I understand that in order to be on the safer side, it'd
|
||||||
|
# be good to have the alpine packages pointing to a very
|
||||||
|
# specific version, but this may break anyone else trying
|
||||||
|
# to use a different version of alpine for one reason or
|
||||||
|
# another. With this in mind, let's ignore DL3018.
|
||||||
|
# SC2086 is about using double quotes to prevent globbing and
|
||||||
|
# word splitting, which can also be ignored for now.
|
||||||
|
# hadolint ignore=DL3018,SC2086
|
||||||
RUN \
|
RUN \
|
||||||
apk --no-cache add bash curl && \
|
apk --no-cache add bash curl && \
|
||||||
ARCH=$(uname -m) && \
|
ARCH=$(uname -m) && \
|
||||||
@@ -20,7 +28,9 @@ RUN \
|
|||||||
mkdir -p ${DESTINATION} && \
|
mkdir -p ${DESTINATION} && \
|
||||||
tar xvf ${WORKDIR}/${KATA_ARTIFACTS} -C ${DESTINATION} && \
|
tar xvf ${WORKDIR}/${KATA_ARTIFACTS} -C ${DESTINATION} && \
|
||||||
rm -f ${WORKDIR}/${KATA_ARTIFACTS} && \
|
rm -f ${WORKDIR}/${KATA_ARTIFACTS} && \
|
||||||
apk del curl
|
apk del curl && \
|
||||||
|
apk --no-cache add jq py3-pip && \
|
||||||
|
pip install --no-cache-dir yq==3.2.3
|
||||||
|
|
||||||
COPY scripts ${DESTINATION}/scripts
|
COPY scripts ${DESTINATION}/scripts
|
||||||
COPY runtimeclasses ${DESTINATION}/runtimeclasses
|
COPY runtimeclasses ${DESTINATION}/runtimeclasses
|
||||||
|
@@ -294,14 +294,11 @@ function cleanup_different_shims_base() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configure_crio_runtime() {
|
function configure_crio_runtime() {
|
||||||
local runtime="kata"
|
local shim="${1}"
|
||||||
local configuration="configuration"
|
local runtime="kata-${shim}"
|
||||||
if [ -n "${1-}" ]; then
|
local configuration="configuration-${shim}"
|
||||||
runtime+="-$1"
|
|
||||||
configuration+="-$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local config_path=$(get_kata_containers_config_path "${1}")
|
local config_path=$(get_kata_containers_config_path "${shim}")
|
||||||
|
|
||||||
local kata_path="/usr/local/bin/containerd-shim-${runtime}-v2"
|
local kata_path="/usr/local/bin/containerd-shim-${runtime}-v2"
|
||||||
local kata_conf="crio.runtime.runtimes.${runtime}"
|
local kata_conf="crio.runtime.runtimes.${runtime}"
|
||||||
@@ -309,7 +306,6 @@ function configure_crio_runtime() {
|
|||||||
|
|
||||||
cat <<EOF | tee -a "$crio_drop_in_conf_file"
|
cat <<EOF | tee -a "$crio_drop_in_conf_file"
|
||||||
|
|
||||||
# Path to the Kata Containers runtime binary that uses the $1
|
|
||||||
[$kata_conf]
|
[$kata_conf]
|
||||||
runtime_path = "${kata_path}"
|
runtime_path = "${kata_path}"
|
||||||
runtime_type = "vm"
|
runtime_type = "vm"
|
||||||
@@ -344,55 +340,28 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configure_containerd_runtime() {
|
function configure_containerd_runtime() {
|
||||||
local runtime="kata"
|
local shim="$2"
|
||||||
local configuration="configuration"
|
local runtime="kata-${shim}"
|
||||||
if [ -n "${2-}" ]; then
|
local configuration="configuration-${shim}"
|
||||||
runtime+="-$2"
|
|
||||||
configuration+="-$2"
|
|
||||||
fi
|
|
||||||
local pluginid=cri
|
local pluginid=cri
|
||||||
|
|
||||||
# if we are running k0s auto containerd.toml generation, the base template is by default version 2
|
# if we are running k0s auto containerd.toml generation, the base template is by default version 2
|
||||||
# we can safely assume to reference the older version of cri
|
# we can safely assume to reference the newer version of cri
|
||||||
if grep -q "version = 2\>" $containerd_conf_file || [ "$1" == "k0s-worker" ] || [ "$1" == "k0s-controller" ]; then
|
if grep -q "version = 2\>" $containerd_conf_file || [ "$1" == "k0s-worker" ] || [ "$1" == "k0s-controller" ]; then
|
||||||
pluginid=\"io.containerd.grpc.v1.cri\"
|
pluginid=\"io.containerd.grpc.v1.cri\"
|
||||||
fi
|
fi
|
||||||
local runtime_table="plugins.${pluginid}.containerd.runtimes.$runtime"
|
local runtime_table=".plugins.${pluginid}.containerd.runtimes.\"${runtime}\""
|
||||||
local runtime_type="io.containerd.$runtime.v2"
|
local runtime_options_table="${runtime_table}.options"
|
||||||
local options_table="$runtime_table.options"
|
local runtime_type=\"io.containerd."${runtime}".v2\"
|
||||||
local config_path="$(get_kata_containers_config_path "$2")/$configuration.toml"
|
local runtime_config_path=\"$(get_kata_containers_config_path "${shim}")/${configuration}.toml\"
|
||||||
if grep -q "\[$runtime_table\]" $containerd_conf_file; then
|
|
||||||
echo "Configuration exists for $runtime_table, overwriting"
|
tomlq -i -t $(printf '%s.runtime_type=%s' ${runtime_table} ${runtime_type}) ${containerd_conf_file}
|
||||||
sed -i "/\[$runtime_table\]/,+1s#runtime_type.*#runtime_type = \"${runtime_type}\"#" $containerd_conf_file
|
tomlq -i -t $(printf '%s.privileged_without_host_devices=true' ${runtime_table}) ${containerd_conf_file}
|
||||||
else
|
tomlq -i -t $(printf '%s.pod_annotations=["io.katacontainers.*"]' ${runtime_table}) ${containerd_conf_file}
|
||||||
cat <<EOF | tee -a "$containerd_conf_file"
|
tomlq -i -t $(printf '%s.ConfigPath=%s' ${runtime_options_table} ${runtime_config_path}) ${containerd_conf_file}
|
||||||
[$runtime_table]
|
|
||||||
runtime_type = "${runtime_type}"
|
|
||||||
privileged_without_host_devices = true
|
|
||||||
pod_annotations = ["io.katacontainers.*"]
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
if grep -q "\[$options_table\]" $containerd_conf_file; then
|
|
||||||
echo "Configuration exists for $options_table, overwriting"
|
|
||||||
sed -i "/\[$options_table\]/,+1s#ConfigPath.*#ConfigPath = \"${config_path}\"#" $containerd_conf_file
|
|
||||||
else
|
|
||||||
cat <<EOF | tee -a "$containerd_conf_file"
|
|
||||||
[$options_table]
|
|
||||||
ConfigPath = "${config_path}"
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${DEBUG}" == "true" ]; then
|
if [ "${DEBUG}" == "true" ]; then
|
||||||
if grep -q "\[debug\]" $containerd_conf_file; then
|
tomlq -i -t '.debug.level = "debug"' ${containerd_conf_file}
|
||||||
sed -i 's/level.*/level = \"debug\"/' $containerd_conf_file
|
|
||||||
else
|
|
||||||
cat <<EOF | tee -a "$containerd_conf_file"
|
|
||||||
[debug]
|
|
||||||
level = "debug"
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,9 +376,6 @@ function configure_containerd() {
|
|||||||
cp -n "$containerd_conf_file" "$containerd_conf_file_backup"
|
cp -n "$containerd_conf_file" "$containerd_conf_file_backup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add default Kata runtime configuration
|
|
||||||
configure_containerd_runtime "$1"
|
|
||||||
|
|
||||||
for shim in "${shims[@]}"; do
|
for shim in "${shims[@]}"; do
|
||||||
configure_containerd_runtime "$1" $shim
|
configure_containerd_runtime "$1" $shim
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user