Skip to content

Commit

Permalink
containerd.runtimes.<name>.options to preserve quotes for non-boolean…
Browse files Browse the repository at this point in the history
… values and normalize boolean values

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.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 Nov 2, 2023
1 parent 267a8c6 commit 93096a3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions roles/container-engine/containerd/templates/config.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ oom_score = {{ containerd_oom_score }}

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.{{ runtime.name }}.options]
{% for key, value in runtime.options.items() %}
{% if value | string != "true" and value | string != "false" %}
{{ key }} = "{{ value }}"
{% else %}
{% set is_bool = value|string|lower in ['true', 'false'] %}
{% set value = value|lower if is_bool else '"' ~ value ~ '"' %}
{{ key }} = {{ value }}
{% endif %}
{% endfor %}
{% endfor %}
{% if kata_containers_enabled %}
Expand Down

0 comments on commit 93096a3

Please sign in to comment.