Skip to content

Commit

Permalink
containerd_additional_runtimes.<name>.options to preserve quotes for …
Browse files Browse the repository at this point in the history
…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.<name>.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.
  • Loading branch information
arno01 committed Jul 22, 2023
1 parent d2383d2 commit cc4986d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion roles/container-engine/containerd/templates/config.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit cc4986d

Please sign in to comment.