fix(container-engine/cri-o): flush Restart crio handler inside the role (#13416)

* fix(container-engine/cri-o): flush Restart crio handler inside the role

During a Kubernetes upgrade (e.g. 1.32 -> 1.33) the cri-o systemd service is
not restarted even though the new cri-o binaries are deployed. This leaves the
node running the old cri-o version (reported as crio://1.32.x after kubelet is
upgraded to 1.33.x); a manual 'systemctl restart crio' fixes it.

The cri-o role notifies 'Restart crio' from several tasks (binary copy,
registries, proxy drop-in, service file, etc.) but never flushes the handler
itself. The handler only fired when the kubernetes/node role ran its own
'meta: flush_handlers' later in the same play. That cross-role dependency is
fragile during upgrades: if kubernetes/node is skipped, tagged out, or the
flush is reordered, the restart is silently dropped.

Route every restart through the single handler: crio.conf and config.json now
notify 'Restart crio' and the ad-hoc 'trigger service restart only when needed'
task is dropped (its restart duplicated what the handler already does, and a
restarted unit also starts a stopped one). Then add 'meta: flush_handlers'
right after the service start task so the pending handlers run as part of this
role regardless of any downstream role's flush timing.

Signed-off-by: Mehrdad Biukian Naeini <mehrdadbiukian@gmail.com>

* test(youki): run youki before cri-o in molecule converge

The converge ran container-engine/cri-o before container-engine/youki, the reverse of the order used by the container-engine role, which installs the runtime roles (kata-containers, gvisor, crun, youki) before the container manager role.

With cri-o flushing its restart handler inside the role, cri-o is now restarted while /usr/local/bin/youki does not exist yet: CRI-O skips the runtime whose binary is missing, so the youki runtime handler is never registered and the verify step fails with 'failed to find runtime handler youki from runtime list map[crun:...]'. Running the roles in the playbook order puts the youki binary in place before cri-o starts.

Signed-off-by: Mehrdad Biukian Naeini <mehrdadbiukian@gmail.com>

---------

Signed-off-by: Mehrdad Biukian Naeini <mehrdadbiukian@gmail.com>
This commit is contained in:
Mehrdad Biukian
2026-09-26 09:50:28 +00:00
committed by GitHub
parent ac72c82651
commit d75f23cba3
2 changed files with 14 additions and 11 deletions
+10 -10
View File
@@ -110,14 +110,14 @@
src: crio.conf.j2 src: crio.conf.j2
dest: /etc/crio/crio.conf dest: /etc/crio/crio.conf
mode: "0644" mode: "0644"
register: config_install notify: Restart crio
- name: Cri-o | install config.json - name: Cri-o | install config.json
template: template:
src: config.json.j2 src: config.json.j2
dest: /etc/crio/config.json dest: /etc/crio/config.json
mode: "0644" mode: "0644"
register: reg_auth_install notify: Restart crio
- name: Cri-o | copy binaries - name: Cri-o | copy binaries
copy: copy:
@@ -275,15 +275,15 @@
daemon_reload: true daemon_reload: true
enabled: true enabled: true
state: started state: started
register: service_start
- name: Cri-o | trigger service restart only when needed # Every config/binary change above notifies "Restart crio", so this flush runs
service: # the pending handlers right away instead of leaving the cri-o restart to the
name: crio # end of the play (where it is lost if kubernetes/node is skipped, tagged out,
state: restarted # or runs in a separate play, as happens during cluster upgrades).
when: # Note: flush_handlers flushes *all* notified handlers in the play, not only
- config_install.changed or reg_auth_install.changed # "Restart crio". See kubernetes-sigs/kubespray#13031.
- not service_start.changed - name: Cri-o | flush handlers to apply cri-o restart
meta: flush_handlers
- name: Cri-o | verify that crio is running - name: Cri-o | verify that crio is running
command: "{{ bin_dir }}/{{ crio_status_command }} info" command: "{{ bin_dir }}/{{ crio_status_command }} info"
@@ -7,5 +7,8 @@
container_manager: crio container_manager: crio
roles: roles:
- role: kubespray_defaults - role: kubespray_defaults
- role: container-engine/cri-o # Keep the order used by roles/container-engine/tasks/main.yml: runtime
# roles run before the container manager, so the youki binary exists when
# cri-o is (re)started and the youki runtime handler is registered.
- role: container-engine/youki - role: container-engine/youki
- role: container-engine/cri-o