8000 k3s: The prune of the Addons requires k3s, rather than k3s being up already by andsens · Pull Request #20 · nixos-homelab/shared · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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
8000
8 changes: 5 additions & 3 deletions nix/modules/k3s/prune.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,17 @@ in
ExecStart = lib.getExe pruneLinks;
};
};
# Restarted with the other on a deploy that changes the links, ordered after it in the same transaction
# Restarted with the other on a deploy that changes the links, and run after k3s is up
systemd.services.k3s-prune-addons = {
description = "Delete the Addons and objects of the manifests removed from the k3s data directory";
after = [
"k3s.service"
"k3s-prune-links.service"
];
# Without k3s there is no API server to wait for: fail at once rather than hold up a boot or a deploy
requisite = [ "k3s.service" ];
# Requires, not Requisite: switch-to-configuration starts each unit in a job of its own, in no fixed order
# (a HashMap), so this one's start can come while k3s is stopped and its start isn't queued yet. Requisite
# then fails the deploy at once; Requires queues k3s' start with this one, and After waits for it
requires = [ "k3s.service" ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ pruneLinks ];
serviceConfig = {
Expand Down
8 changes: 8 additions & 0 deletions nix/tests/k3s.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
node.succeed(f"ln -s $(readlink -f /etc/k3s-prune-test/prune-test-boot.yaml) {manifests}/prune-test-boot.yaml")
node.wait_until_succeeds(f"{kubectl} -n default get configmap prune-test-boot", timeout=120)

with subtest("k3s: the prune of the Addons starts while k3s is stopped, starting k3s rather than failing"):
# As switch-to-configuration does: k3s stopped, then a start job for each unit on its own, in no fixed order. The
# prune's start may come first, before any start of k3s is queued
node.succeed("systemctl stop k3s-prune-addons.service k3s.service")
node.succeed("systemctl start k3s-prune-addons.service")
node.succeed("systemctl is-active k3s.service k3s-prune-addons.service")
node.wait_until_succeeds(f"{kubectl} get --raw /readyz", timeout=300)

with subtest("shutdown: a reboot drains the node first, leaving no Failed pods and no cordon"):
# Through logind, which sends PrepareForShutdown; the driver's reboot() presses Ctrl+Alt+Del, which doesn't. The
# driver runs QEMU with -no-reboot, so the reboot ends the VM, and the test starts it again
Expand Down
Loading
0