From cc4986dfab084b9026e08357815962203db6d7c5 Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Sat, 22 Jul 2023 19:59:52 +0200 Subject: [PATCH] containerd_additional_runtimes..options to preserve quotes for non-boolean values (#9913) This commit modifies the Jinja2 template for generating the containerd configuration file to handle a specific requirement: preserving quotes for non-boolean values in `containerd_additional_runtimes..options`. The update is necessary due to the mixed data types in the options field: 1. Boolean values (true, false) and their string equivalents ("true", "false") should be rendered without quotes. 2. Non-boolean string values should be rendered with quotes. The logic implemented checks if a value is a boolean or the string representation of a boolean. If it is, we ensure it's rendered as a lowercase `true` or `false` without quotes. If the value is not a boolean or a string equivalent of a boolean, we render it with quotes, preserving the original formatting. While the logic may seem verbose, it's necessary to accommodate the differing requirements for boolean and non-boolean values within the configuration file, ensuring the generated configurations are correctly formatted and functional. --- roles/container-engine/containerd/templates/config.toml.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/container-engine/containerd/templates/config.toml.j2 b/roles/container-engine/containerd/templates/config.toml.j2 index e47069ecb3e..f6d1d0c84a4 100644 --- a/roles/container-engine/containerd/templates/config.toml.j2 +++ b/roles/container-engine/containerd/templates/config.toml.j2 @@ -35,7 +35,8 @@ oom_score = {{ containerd_oom_score }} [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.{{ runtime.name }}.options] {% for key, value in runtime.options.items() %} - {{ key }} = {{ value }} + {{ key }} = {% if value is boolean %}{{ value|lower }}{% elif value is string and (value|lower in ['true', 'false']) %}{{ value|lower }}{% else %}"{{ value }}"{% endif %} + {% endfor %} {% endfor %} {% if kata_containers_enabled %}