Skip to content

fix: upgrade stopped workers when --force given, not rejoin them - #1270

Merged
kke merged 1 commit into
k0sproject:mainfrom
amlaban65:upgrade-stopped-workers-with-force
Nov 16, 2026
Merged

kke merged 1 commit into
k0sproject:mainfrom
amlaban65:upgrade-stopped-workers-with-force

Conversation

@amlaban65

Copy link
Copy Markdown
Contributor

Fixes #1118

This follows the two steps kke outlined in the issue.

Problem

If k0s is installed as a service on a host but isn't running, GatherK0sFacts stops the apply with:

k0s doesn't appear to be running but has been installed as a service at ... - please remove it or start the service

--force gets past this check, but the message doesn't mention it. Even with --force, the host keeps K0sRunningVersion == nil and NeedsUpgrade == false. So UpgradeWorkers skips it and InstallWorkers treats it as a fresh join: it creates a new token and reinstalls the service. If the node then doesn't become Ready, InstallWorkers.CleanUp runs k0s reset on it. That's not what you'd expect from an upgrade.

Changes

The not-running-but-installed branch of investigateK0s now calls a new handleStoppedService helper:

  • Without --force, the error now ends with please remove it, start the service or use --force to proceed anyway.
  • With --force on a worker, the helper calls the existing needsUpgrade and stores the result in h.Metadata.NeedsUpgrade. The binary providers already fall back to the installed binary version when nothing is running. So a stopped worker with an outdated binary now goes through UpgradeWorkers: stop the service (a no-op here), replace the binary, reinstall and start the service. InstallWorkers skips it.
  • Controllers keep the old --force behaviour. A stopped controller has no running version, so it can also end up as the fallback leader for InitializeK0s. Marking it for upgrade as well would send the same host through both phases. That case needs more thought, so I left it out.

A stopped worker whose binary already matches the target version still takes the existing InstallWorkers path. Only the version mismatch from the issue is rerouted. Without --no-drain, UpgradeWorkers still cordons and drains the node through the leader, as for any other upgrade. The issue's workaround is --force --no-drain.

Testing

  • New TestHandleStoppedService with four cases:
    • without --force, the error mentions --force;
    • with --force, an outdated stopped worker is marked for upgrade;
    • an up-to-date stopped worker is not marked;
    • a stopped controller is not marked.
  • I checked that the test fails against the old logic, moved into the same helper. Two cases fail: the error doesn't contain --force, and NeedsUpgrade stays false. Both pass with the change.
  • go test ./... and go vet ./phase/ pass, and gofmt reports nothing for the changed files. My environment didn't have Go 1.27, so I ran these with Go 1.25.1 against local copies of the dependencies, with small compatibility shims in the rig v2 copy only. The repository's own files are unchanged apart from this diff.
  • I didn't run an actual apply against a stopped worker, and I didn't run the smoke tests.

@kke
kke requested a balanced review from Copilot November 16, 2026 09:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŸข Approval recommended

No active review issues remain for the change to upgrade stopped workers with outdated binaries when --force is used.

No open issues ๐ŸŽ‰

What changed in this PR

Updates k0sctlโ€™s apply flow so stopped workers with outdated binaries follow the upgrade path when --force is used, rather than being treated as fresh joins. This addresses the stopped-node upgrade scenario in #1118.

Changes:

  • Adds a stopped-service helper that marks workers for upgrade using the existing version check.
  • Mentions --force in the stopped-service error while preserving existing behavior for controllers and up-to-date workers.
  • Adds four unit-test cases covering forced and non-forced handling.
File Description
phase/โ€‹gather_k0s_facts.go Routes stopped-service handling through the new helper and marks outdated workers for upgrade.
phase/โ€‹gather_k0s_facts_test.go Tests the error guidance and upgrade decisions for stopped workers and controllers.

Review effort: Balanced

When k0s is installed as a service but not running, the error now says
that --force can be used to proceed. With --force, a stopped worker whose
installed k0s binary differs from the target version is marked for
upgrade, so it goes through UpgradeWorkers instead of being treated as a
fresh join by InstallWorkers, whose cleanup can reset the host.

Fixes k0sproject#1118

Signed-off-by: Ahmed Laban <79754427+amlaban65@users.noreply.github.com>
@kke
kke force-pushed the upgrade-stopped-workers-with-force branch from b60ad12 to 0bbca01 Compare November 16, 2026 11:36
@kke kke changed the title fix: upgrade stopped workers with --force instead of rejoining them fix: upgrade stopped workers when --force given, not rejoin them Nov 16, 2026
@kke
kke merged commit b2984ca into k0sproject:main Nov 16, 2026
1 check 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.

k0sctl should tolerate down node for update with no drain option

3 participants