Skip to content

Commit

Permalink
Hack to check systemd version for service files validation
Browse files Browse the repository at this point in the history
factory-reset.target was introduced in system 250, same version as the
aliasing feature we need for verifying systemd services with ansible.
So we only actually executes the validation if that target is present.

This is an horrible hack which should be reverted as soon as we drop
support for distributions with systemd<250.
  • Loading branch information
VannTen committed Nov 17, 2023
1 parent 6b72d3f commit a4096ae
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion roles/container-engine/containerd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
src: containerd.service.j2
dest: /etc/systemd/system/containerd.service
mode: 0644
validate: "systemd-analyze verify %s:containerd.service"
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:containerd.service'"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
notify: Restart containerd

- name: Containerd | Ensure containerd directories exist
Expand Down
4 changes: 3 additions & 1 deletion roles/container-engine/cri-dockerd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
mode: 0644
validate: "systemd-analyze verify %s:{{ item }}"
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:{{ item }}'"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
with_items:
- cri-dockerd.service
- cri-dockerd.socket
Expand Down
8 changes: 6 additions & 2 deletions roles/etcd/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
dest: /etc/systemd/system/etcd.service
backup: yes
mode: 0644
validate: "systemd-analyze verify %s:etcd-{{ etcd_deployment_type }}.service"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:etcd-{{ etcd_deployment_type }}.service'"
when: is_etcd_master and etcd_cluster_setup

- name: Configure | Copy etcd-events.service systemd file
Expand All @@ -60,7 +62,9 @@
dest: /etc/systemd/system/etcd-events.service
backup: yes
mode: 0644
validate: "systemd-analyze verify %s:etcd-events-{{ etcd_deployment_type }}.service"
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:etcd-events-{{ etcd_deployment_type }}.service'"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
when: is_etcd_master and etcd_events_cluster_setup

- name: Configure | reload systemd
Expand Down
4 changes: 3 additions & 1 deletion roles/kubernetes/control-plane/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
mode: 0644
validate: "systemd-analyze verify %s:{{item}}"
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:{{item}}'"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
with_items:
- k8s-certs-renew.service
- k8s-certs-renew.timer
Expand Down
4 changes: 3 additions & 1 deletion roles/kubernetes/node/tasks/kubelet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
dest: "/etc/systemd/system/kubelet.service"
backup: "yes"
mode: 0600
validate: "systemd-analyze verify %s:kubelet.service"
validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:kubelet.service'"
# FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
# Remove once we drop support for systemd < 250
notify: Node | restart kubelet
tags:
- kubelet
Expand Down

0 comments on commit a4096ae

Please sign in to comment.