Skip to content

fix: override systemd unit#110

Merged
anson627 merged 2 commits intomainfrom
hbc/systemd-unit-force-enable
Mar 3, 2026
Merged

fix: override systemd unit#110
anson627 merged 2 commits intomainfrom
hbc/systemd-unit-force-enable

Conversation

@bcho
Copy link
Member

@bcho bcho commented Mar 3, 2026

This pull request refactors how systemd unit and drop-in files are managed across several components, introducing idempotent "ensure" methods that only write files when necessary and centralizing logic for starting and reloading units. The changes improve reliability and reduce unnecessary restarts or reloads by tracking when files have actually changed.

Systemd file management improvements:

  • Replaces previous WriteUnitFile and WriteDropInFile methods with new EnsureUnitFile and EnsureDropInFile methods in the systemd.Manager interface, which only write files if their content has changed or if the file does not exist. These methods now return a boolean indicating whether the file was updated. (pkg/systemd/types.go, pkg/systemd/dbus.go) [1] [2]
  • Updates all usages in kubelet, kubeadm, and cri components to use the new "ensure" methods, removing manual checks for file existence and content. (components/kubelet/v20260301/kubelet_service.go, components/kubeadm/v20260301/join.go, components/cri/v20260301/service.go) [1] [2] [3] [4]

Unit lifecycle and reload logic centralization:

  • Introduces a new EnsureUnitRunning helper function that encapsulates logic for reloading the systemd daemon and restarting or starting units only when necessary, based on whether unit files or drop-ins were updated. (pkg/systemd/ensure.go)
  • Refactors component logic to use this new helper, simplifying code and ensuring consistent behavior across services. (components/kubelet/v20260301/kubelet_service.go, components/cri/v20260301/service.go) [1] [2]

Code cleanup:

  • Removes unused error handling and file existence checks, as these are now handled by the new "ensure" methods. (components/kubelet/v20260301/kubelet_service.go, pkg/systemd/dbus.go) [1] [2]

These changes make systemd unit management more robust and reduce unnecessary operations, improving both reliability and maintainability.

@bcho bcho force-pushed the hbc/systemd-unit-force-enable branch from c13d108 to 157c161 Compare March 3, 2026 04:53
@bcho bcho temporarily deployed to e2e-testing March 3, 2026 04:53 — with GitHub Actions Inactive
@bcho bcho marked this pull request as ready for review March 3, 2026 05:53
@anson627 anson627 merged commit 4c0ee9f into main Mar 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants