-
Notifications
You must be signed in to change notification settings - Fork 2
fix(prepare): enable containerd device_ownership_from_security_context for CDI block imports #47
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,19 @@ | |
| state: restarted | ||
| failed_when: false # tolerated: same reason as the enable task below | ||
|
|
||
| - name: Restart k3s to apply containerd config | ||
| ansible.builtin.systemd: | ||
| name: "{{ item }}" | ||
| state: restarted | ||
| loop: | ||
| - k3s | ||
| - k3s-agent | ||
| # Only the unit matching this node's role exists; the other is | ||
| # absent, and on the full-pipeline run prepare executes before | ||
| # k3s is installed (the drop-in is then read at first k3s start). | ||
| # failed_when: false tolerates both — a missing unit is not an error. | ||
| failed_when: false | ||
|
Comment on lines
+125
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using - name: Restart k3s to apply containerd config
ansible.builtin.systemd:
name: "{{ item.item }}"
state: restarted
loop: "{{ k3s_services_stat.results | default([]) }}"
when: item.stat.exists | default(false) |
||
|
|
||
| tasks: | ||
| - name: Create k3s_cluster group for k3s.orchestration | ||
| ansible.builtin.group_by: | ||
|
|
@@ -188,6 +201,41 @@ | |
| | map(attribute='item') | ||
| | list }} | ||
|
|
||
| # CDI (Containerized Data Importer) streams VM disk images into raw | ||
| # block volumes from a NON-root importer pod. containerd only chowns | ||
| # the block device to the pod's SecurityContext UID/GID when | ||
| # device_ownership_from_security_context is enabled on the CRI | ||
| # plugin, and k3s ships it disabled. Without it the importer dies | ||
| # with "blockdev: cannot open /dev/cdi-block-volume: Permission | ||
| # denied", the DataVolume hangs in ImportInProgress, and every VM | ||
| # that references the disk stays Pending. | ||
| # | ||
| # The drop-in is merged by containerd on top of k3s's generated | ||
| # config.toml via the config-v3.toml.d import glob — read at first | ||
| # k3s start (full pipeline) or applied by the handler on re-runs | ||
| # against a running cluster. config-v3.toml.d and | ||
| # io.containerd.cri.v1.runtime are the containerd 2.x (config | ||
| # version 3) paths shipped by current k3s; override | ||
| # cozystack_k3s_containerd_dropin_dir for a containerd 1.x cluster. | ||
| - name: Ensure k3s containerd config drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}" | ||
| state: directory | ||
| mode: "0755" | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
|
Comment on lines
+220
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To safely restart k3s only when it is actually installed, we can add a task to check if the systemd unit files exist using - name: Check if k3s services are installed
ansible.builtin.stat:
path: "/etc/systemd/system/{{ item }}.service"
loop:
- k3s
- k3s-agent
register: k3s_services_stat
when: cozystack_enable_kubevirt | default(true) | bool
- name: Ensure k3s containerd config drop-in directory exists
ansible.builtin.file:
path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}"
state: directory
mode: "0755"
when: cozystack_enable_kubevirt | default(true) | bool |
||
|
|
||
| - name: Enable device_ownership_from_security_context for CDI block imports | ||
| ansible.builtin.copy: | ||
| dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml" | ||
| mode: "0644" | ||
| content: | | ||
| version = 3 | ||
|
|
||
| [plugins.'io.containerd.cri.v1.runtime'] | ||
| device_ownership_from_security_context = true | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
| notify: Restart k3s to apply containerd config | ||
|
Comment on lines
+227
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README and CHANGELOG state that containerd 1.x clusters are supported by overriding the drop-in directory and adjusting the plugin table. However, the config version ( - name: Enable device_ownership_from_security_context for CDI block imports
ansible.builtin.copy:
dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml"
mode: "0644"
content: |
version = {{ cozystack_k3s_containerd_config_version | default(3) }}
[plugins.'{{ cozystack_k3s_containerd_cri_plugin | default("io.containerd.cri.v1.runtime") }}']
device_ownership_from_security_context = true
when: cozystack_enable_kubevirt | default(true) | bool
notify: Restart k3s to apply containerd config |
||
|
|
||
| - name: Ensure multipath drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: /etc/multipath/conf.d | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,19 @@ | |
| state: restarted | ||
| failed_when: false # tolerated: same reason as the enable task below | ||
|
|
||
| - name: Restart k3s to apply containerd config | ||
| ansible.builtin.systemd: | ||
| name: "{{ item }}" | ||
| state: restarted | ||
| loop: | ||
| - k3s | ||
| - k3s-agent | ||
| # Only the unit matching this node's role exists; the other is | ||
| # absent, and on the full-pipeline run prepare executes before | ||
| # k3s is installed (the drop-in is then read at first k3s start). | ||
| # failed_when: false tolerates both — a missing unit is not an error. | ||
| failed_when: false | ||
|
Comment on lines
+120
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using - name: Restart k3s to apply containerd config
ansible.builtin.systemd:
name: "{{ item.item }}"
state: restarted
loop: "{{ k3s_services_stat.results | default([]) }}"
when: item.stat.exists | default(false) |
||
|
|
||
| tasks: | ||
| - name: Create k3s_cluster group for k3s.orchestration | ||
| ansible.builtin.group_by: | ||
|
|
@@ -183,6 +196,41 @@ | |
| | map(attribute='item') | ||
| | list }} | ||
|
|
||
| # CDI (Containerized Data Importer) streams VM disk images into raw | ||
| # block volumes from a NON-root importer pod. containerd only chowns | ||
| # the block device to the pod's SecurityContext UID/GID when | ||
| # device_ownership_from_security_context is enabled on the CRI | ||
| # plugin, and k3s ships it disabled. Without it the importer dies | ||
| # with "blockdev: cannot open /dev/cdi-block-volume: Permission | ||
| # denied", the DataVolume hangs in ImportInProgress, and every VM | ||
| # that references the disk stays Pending. | ||
| # | ||
| # The drop-in is merged by containerd on top of k3s's generated | ||
| # config.toml via the config-v3.toml.d import glob — read at first | ||
| # k3s start (full pipeline) or applied by the handler on re-runs | ||
| # against a running cluster. config-v3.toml.d and | ||
| # io.containerd.cri.v1.runtime are the containerd 2.x (config | ||
| # version 3) paths shipped by current k3s; override | ||
| # cozystack_k3s_containerd_dropin_dir for a containerd 1.x cluster. | ||
| - name: Ensure k3s containerd config drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}" | ||
| state: directory | ||
| mode: "0755" | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
|
Comment on lines
+215
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To safely restart k3s only when it is actually installed, we can add a task to check if the systemd unit files exist using - name: Check if k3s services are installed
ansible.builtin.stat:
path: "/etc/systemd/system/{{ item }}.service"
loop:
- k3s
- k3s-agent
register: k3s_services_stat
when: cozystack_enable_kubevirt | default(true) | bool
- name: Ensure k3s containerd config drop-in directory exists
ansible.builtin.file:
path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}"
state: directory
mode: "0755"
when: cozystack_enable_kubevirt | default(true) | bool |
||
|
|
||
| - name: Enable device_ownership_from_security_context for CDI block imports | ||
| ansible.builtin.copy: | ||
| dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml" | ||
| mode: "0644" | ||
| content: | | ||
| version = 3 | ||
|
|
||
| [plugins.'io.containerd.cri.v1.runtime'] | ||
| device_ownership_from_security_context = true | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
| notify: Restart k3s to apply containerd config | ||
|
Comment on lines
+222
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README and CHANGELOG state that containerd 1.x clusters are supported by overriding the drop-in directory and adjusting the plugin table. However, the config version ( - name: Enable device_ownership_from_security_context for CDI block imports
ansible.builtin.copy:
dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml"
mode: "0644"
content: |
version = {{ cozystack_k3s_containerd_config_version | default(3) }}
[plugins.'{{ cozystack_k3s_containerd_cri_plugin | default("io.containerd.cri.v1.runtime") }}']
device_ownership_from_security_context = true
when: cozystack_enable_kubevirt | default(true) | bool
notify: Restart k3s to apply containerd config |
||
|
|
||
| - name: Ensure multipath drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: /etc/multipath/conf.d | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,19 @@ | |
| # IS consulted downstream.) | ||
| failed_when: false | ||
|
|
||
| - name: Restart k3s to apply containerd config | ||
| ansible.builtin.systemd: | ||
| name: "{{ item }}" | ||
| state: restarted | ||
| loop: | ||
| - k3s | ||
| - k3s-agent | ||
| # Only the unit matching this node's role exists; the other is | ||
| # absent, and on the full-pipeline run prepare executes before | ||
| # k3s is installed (the drop-in is then read at first k3s start). | ||
| # failed_when: false tolerates both — a missing unit is not an error. | ||
| failed_when: false | ||
|
Comment on lines
+141
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using - name: Restart k3s to apply containerd config
ansible.builtin.systemd:
name: "{{ item.item }}"
state: restarted
loop: "{{ k3s_services_stat.results | default([]) }}"
when: item.stat.exists | default(false) |
||
|
|
||
| tasks: | ||
| - name: Create k3s_cluster group for k3s.orchestration | ||
| ansible.builtin.group_by: | ||
|
|
@@ -229,6 +242,41 @@ | |
| | map(attribute='item') | ||
| | list }} | ||
|
|
||
| # CDI (Containerized Data Importer) streams VM disk images into raw | ||
| # block volumes from a NON-root importer pod. containerd only chowns | ||
| # the block device to the pod's SecurityContext UID/GID when | ||
| # device_ownership_from_security_context is enabled on the CRI | ||
| # plugin, and k3s ships it disabled. Without it the importer dies | ||
| # with "blockdev: cannot open /dev/cdi-block-volume: Permission | ||
| # denied", the DataVolume hangs in ImportInProgress, and every VM | ||
| # that references the disk stays Pending. | ||
| # | ||
| # The drop-in is merged by containerd on top of k3s's generated | ||
| # config.toml via the config-v3.toml.d import glob — read at first | ||
| # k3s start (full pipeline) or applied by the handler on re-runs | ||
| # against a running cluster. config-v3.toml.d and | ||
| # io.containerd.cri.v1.runtime are the containerd 2.x (config | ||
| # version 3) paths shipped by current k3s; override | ||
| # cozystack_k3s_containerd_dropin_dir for a containerd 1.x cluster. | ||
| - name: Ensure k3s containerd config drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}" | ||
| state: directory | ||
| mode: "0755" | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
|
Comment on lines
+261
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To safely restart k3s only when it is actually installed, we can add a task to check if the systemd unit files exist using - name: Check if k3s services are installed
ansible.builtin.stat:
path: "/etc/systemd/system/{{ item }}.service"
loop:
- k3s
- k3s-agent
register: k3s_services_stat
when: cozystack_enable_kubevirt | default(true) | bool
- name: Ensure k3s containerd config drop-in directory exists
ansible.builtin.file:
path: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}"
state: directory
mode: "0755"
when: cozystack_enable_kubevirt | default(true) | bool |
||
|
|
||
| - name: Enable device_ownership_from_security_context for CDI block imports | ||
| ansible.builtin.copy: | ||
| dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml" | ||
| mode: "0644" | ||
| content: | | ||
| version = 3 | ||
|
|
||
| [plugins.'io.containerd.cri.v1.runtime'] | ||
| device_ownership_from_security_context = true | ||
| when: cozystack_enable_kubevirt | default(true) | bool | ||
| notify: Restart k3s to apply containerd config | ||
|
Comment on lines
+268
to
+278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README and CHANGELOG state that containerd 1.x clusters are supported by overriding the drop-in directory and adjusting the plugin table. However, the config version ( - name: Enable device_ownership_from_security_context for CDI block imports
ansible.builtin.copy:
dest: "{{ cozystack_k3s_containerd_dropin_dir | default('/var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.d') }}/10-cozystack-cri.toml"
mode: "0644"
content: |
version = {{ cozystack_k3s_containerd_config_version | default(3) }}
[plugins.'{{ cozystack_k3s_containerd_cri_plugin | default("io.containerd.cri.v1.runtime") }}']
device_ownership_from_security_context = true
when: cozystack_enable_kubevirt | default(true) | bool
notify: Restart k3s to apply containerd config |
||
|
|
||
| - name: Ensure multipath drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: /etc/multipath/conf.d | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version bump violates collection versioning policy.
The collection version is being bumped from 1.4.2 to 1.4.3 for a bugfix (containerd CRI configuration), but the coding guidelines state: "Collection version is inherited from
cozystack/cozystackand tracks the upstream Cozystack chart version (the value inroles/cozystack/defaults/main.yml:cozystack_chart_version). Do NOT bump the collection version just because a PR adds features or fixes bugs."Unless
cozystack_chart_versioninroles/cozystack/defaults/main.ymlhas also been updated to 1.4.3 (which is not shown in the provided files), this version bump should be reverted. The fix should be released as part of the next version that syncs with an upstream Cozystack chart release.As per coding guidelines: Collection version is inherited from cozystack/cozystack and tracks the upstream Cozystack chart version (the value in roles/cozystack/defaults/main.yml:cozystack_chart_version). Do NOT bump the collection version just because a PR adds features or fixes bugs.
🤖 Prompt for AI Agents