Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

containerd.runtimes.<name>.options to preserve quotes for non-boolean values and normalize boolean values (#9913) #10307

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I would prefer the syntax above in the if case, it's more readable IMO, something like that:

Suggested change
{% set is_bool = value|string|lower in ['true', 'false'] %}
{% if value | string | lower in ['true', 'false'] %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the next line where is_bool gets used.

If I go with your preferred way, the next line will have to look as follows:

{% set value = value|lower if (value | string | lower in ['true', 'false']) else '"' ~ value ~ '"' %}

which makes it way harder to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would only update this line and keep the if/else

{% if value | string | lower in ['true', 'false'] %}
            {{ key }} = "{{ value }}"
{% else %}
            {{ key }} = {{ value }}
{% endif %}

{% set value = value|lower if is_bool else '"' ~ value ~ '"' %}
{{ key }} = {{ value }}
{% endif %}
{% endfor %}
{% endfor %}
{% if kata_containers_enabled %}
Expand Down