Skip to content

CKS: retry the upgrade manifests while the API server restarts - #14912

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-upgrade-apply-retry
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-upgrade-apply-retry

Conversation

@bhouse-nexthop

@bhouse-nexthop bhouse-nexthop commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The first control node's upgrade attempt always failed. upgrade-kubernetes.sh applies network.yaml and the dashboard manifest right after it restarts containerd and kubelet, while the upgraded API server is still restarting. kubectl apply failed with unexpected EOF, then with User "kubernetes-admin" cannot get resource "customresourcedefinitions" until the API server authorized requests again. Only a rerun of the whole script got past it, so with cloud.kubernetes.cluster.upgrade.retries=0 every upgrade stopped at the control node. Details in #14911.

The script now applies these two manifests through apply_manifest, which retries every 10 seconds while kubectl apply fails:

Setting Value Why
APPLY_RETRY_TIMEOUT 180 s per manifest no retry starts after this
APPLY_ATTEMPT_TIMEOUT 90 s an apply that hangs on a half-up API server is stopped and retried
APPLY_RETRY_SLEEP 10 s

When the retries run out the script fails as before, and the management server's own retries still apply. If the API server never comes back, the script fails after about 3 to 4.5 minutes per manifest instead of at once.

It does not wait on /readyz first: CKS accepts Kubernetes versions before 1.16, which don't have it, and the EOF can also happen in the middle of an apply.

Only upgrade-kubernetes.sh changes, and only the first control node runs these applies. On main the dashboard step is the headlamp.yaml / dashboard.yaml choice; both applies there should use apply_manifest when this is merged forward.

Fixes: #14911

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

apply_manifest with a stub kubectl, under bash -e:

Stub Result
fails twice, then works applied on the 3rd attempt, script continues
always fails (window shortened to 25 s) 3 attempts, ERROR: Unable to apply ..., script exits 1, no attempt after the window
first attempt hangs (attempt timeout shortened to 5 s) attempt killed, applied on the next one

Lab, KVM with Ceph RBD primary storage, CKS cluster of 1 control and 2 worker nodes upgraded from Kubernetes 1.33.1 to 1.34.7 with cloud.kubernetes.cluster.upgrade.retries=0, on a main build with an earlier version of this change (120 s window, 60 s per attempt): the upgrade passed with no failed script attempt. Before the change the control node's first attempt failed in 4 of 4 upgrades. This commit on a 4.22 build, same setup with a 4.22-built ISO and retries 0: 15 of 15 checks passed, no failed script attempt (report in the comments).

How did you try to break this feature and the system with this change?

  • set -e still ends the script when the retries run out: kubectl runs in the until condition, and apply_manifest returns 1 from a plain call.
  • Re-applying after an interrupted apply is safe: objects the server already stored carry their last-applied annotation, so the next attempt patches them.
  • A manifest that can never apply (bad YAML, an immutable field) now fails after about 3 minutes instead of at once, with the same kubectl error followed by ERROR: Unable to apply <file>.
  • Output is printed at least every ~100 s, so the management server's SSH read does not time out while the script retries.

upgrade-kubernetes.sh applied the CNI and dashboard manifests on the
first control node right after restarting containerd and kubelet, while
the upgraded API server was still restarting. kubectl failed with
"unexpected EOF", then with "Forbidden" until the API server authorized
requests again, so the first upgrade attempt of the control node failed
and only a retry of the whole script got past it. With
cloud.kubernetes.cluster.upgrade.retries=0 the upgrade stopped there.

Apply each manifest again every 10 seconds while it fails. No retry
starts more than 180 seconds after the first attempt, and each attempt
is stopped after 90 seconds, so an apply that hangs on a restarting API
server is retried too.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 18.34%. Comparing base (a8735b2) to head (dfd2b00).

Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14912   +/-   ##
=========================================
  Coverage     18.34%   18.34%           
+ Complexity    16671    16670    -1     
=========================================
  Files          5939     5939           
  Lines        537817   537817           
  Branches      65938    65938           
=========================================
  Hits          98640    98640           
  Misses       427954   427954           
  Partials      11223    11223           
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.43% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator Author

Tested on a KVM lab running a 4.22 build that includes this commit. Primary storage is Ceph RBD. The CKS cluster has 1 control and 2 worker nodes with Calico. It was upgraded from Kubernetes 1.33.1 to 1.34.7, using a binaries ISO made with the 4.22 create-kubernetes-binaries-iso.sh, with cloud.kubernetes.cluster.upgrade.retries=0.

Result: 15 of 15 checks passed.

Check Result
Upgrade script attempts that failed (unable to upgrade Kubernetes node in the log) 0
Cluster state Upgrading, then Running at 1.34.7
Nodes after the upgrade all 3 Ready at v1.34.7 and schedulable
Order control node at v1.34.7 before any worker; one Upgrading node log line per node, control first
Nodes cordoned at once never more than 1
ISO attached after the upgrade none

The upgrade took 390 s.

Without this change, earlier upgrades on the same lab failed the control node's first attempt with the Forbidden error from #14911 (unable to upgrade Kubernetes node : <cluster>-control-..., retries left: 3), and on a main build the same failure happened in 4 of 4 upgrades.

The cluster was deleted afterwards and the setting was put back to 3.

Not tested: clusters with more than one control node (only the first control node runs these applies), and an API server that never comes back (the stub test in the description covers that path).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant