kubeblocks icon indicating copy to clipboard operation
kubeblocks copied to clipboard

fix: keep recoverable ops failures in progress

Open weicao opened this issue 6 months ago • 3 comments

What happened

An Elasticsearch restart OpsRequest was marked Failed while the target Pod later became Ready and the Elasticsearch cluster stayed green.

The preserved evidence shows the Pod did have a real failed/waiting history during recreate:

Error: failed to sync configmap cache: timed out waiting for the condition

That history should remain visible on the Pod / InstanceSet side. The bug is that restart Ops used the recoverable historical failure as an immediate terminal Ops result, even though the component had not become Failed and the instance could still recover.

Fixes #10300

Root cause

Rolling Ops progress counted a failed progress detail as completed and then finalized the whole OpsRequest as Failed as soon as all expected instances had either succeeded or failed.

That is too eager for restart-style rolling operations: a recreated Pod can have a real temporary failure signal and then become available later. If the component is still not Failed, Ops should keep observing instead of freezing that historical failure as the final operation result.

Fix

Do not change Pod failure detection.

Instead, make component Ops progress more robust:

  • failed progress details are still recorded;
  • when a component is not in Failed, failed progress details do not count toward completed progress;
  • the OpsRequest remains running so a later recovered instance can overwrite the failed detail with Succeed;
  • if the component is actually Failed, existing terminal failure behavior is preserved.

Validation

Local validation:

go test ./pkg/controllerutil -run TestPodIsReady -count=1
KUBEBUILDER_ASSETS='/Users/wei/Library/Application Support/io.kubebuilder.envtest/k8s/1.26.1-darwin-arm64' go test ./pkg/operations -run TestAPIs -count=1
git diff --check

The new envtest covers the contract: a restart Ops with a failed progress detail stays Running while the component is still Running, reports 2/3, and then succeeds once the instance recovers. The existing failed-component test still expects Ops Failed.

Evidence boundary: the ES field occurrence is N=1. This PR fixes the deterministic Ops progress contract that turned a recoverable failure history into a terminal Ops failure. It is not a release-ready claim; ES needs fresh exact-head runtime validation after this new head is sideloaded.

weicao avatar May 27 '26 12:05 weicao

Auto Cherry-pick Instructions

Usage:
  - /nopick: Not auto cherry-pick when PR merged.
  - /pick: release-x.x [release-x.x]: Auto cherry-pick to the specified branch when PR merged.

Example:
  - /nopick
  - /pick release-1.1

apecloud-bot avatar May 27 '26 12:05 apecloud-bot

Supersedes #10298. The patch commit is unchanged (403be1eb0); #10298 was closed because its branch name was rejected by PR pre-check. This PR uses the valid bugfix/es-pod-waiting-failure branch.

weicao avatar May 27 '26 12:05 weicao

Codecov Report

:x: Patch coverage is 83.33333% with 9 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 52.87%. Comparing base (bd81433) to head (72850c9). :warning: Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
pkg/operations/ops_progress_util.go 75.86% 5 Missing and 2 partials :warning:
pkg/operations/ops_comp_helper.go 94.73% 1 Missing :warning:
pkg/operations/ops_manager.go 80.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10299      +/-   ##
==========================================
+ Coverage   52.83%   52.87%   +0.03%     
==========================================
  Files         533      533              
  Lines       61213    61267      +54     
==========================================
+ Hits        32343    32393      +50     
+ Misses      25621    25615       -6     
- Partials     3249     3259      +10     
Flag Coverage Δ
unittests 52.87% <83.33%> (+0.03%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar May 27 '26 12:05 codecov[bot]

The deeper issue here is that Ops is treating a shared pod/instance failure signal as an Ops terminal failure. That signal can still be useful for ITS/Component controllers as an observation/repair input, but Ops needs its own interpretation: whether this signal is terminal for the current operation, recoverable, or just something to keep observing.

This PR changes the shared component Ops aggregation logic instead: any failed progress detail is no longer terminal while the Component phase is not Failed. That broadens a restart-specific transient failure workaround to every caller of reconcileActionWithComponentOps (restart/start/stop/upgrade/hscale/vscale), and also makes FailedProgressStatus mean both "terminal failure" and "historical recoverable signal" depending on Component phase.

The fix should be scoped at the Ops failure-consumption layer: keep the shared failure signal, but classify it per Ops type/stage before writing terminal Failed progress. For restart/recreate-style Ops, transient pod waiting can be recorded as event/message or kept under observation, but FailedProgressStatus should remain reserved for actual terminal operation failure.

leon-ape avatar Jun 01 '26 02:06 leon-ape

There is also an unbounded-running case introduced here. If a progress detail becomes Failed, the Component phase is not Failed, and that instance never recovers, reconcileActionWithComponentOps now subtracts the failed detail from completed progress and keeps the OpsRequest Running.

Because OpsRequest timeoutSeconds is optional and 0 means no timeout, this can leave the OpsRequest Running forever and block later queued Ops for the cluster. Component phase is too coarse and asynchronous to prove that a failed progress detail is recoverable.

Please add a bounded failure policy for this path, for example a grace/observation window after the failed detail timestamp, or scope this recoverable behavior only to the specific restart/recreate case with tests. A test should cover: failed progress persists, Component is not Failed, the pod never recovers, and the Ops must not remain Running indefinitely.

leon-ape avatar Jun 01 '26 02:06 leon-ape

Addressed the review comments in head 03be32fb3410456301c323406010c49a8be3f617.

What changed:

  • removed the broad Component-phase-based failure suppression from shared component Ops aggregation;
  • scoped the recoverable behavior to restart progress consumption;
  • restart now observes failed-and-timed-out instances as Processing only for a bounded 5-minute window and requeues at the deadline;
  • if the instance recovers, the detail can become Succeed; if it does not recover before the deadline, the detail becomes Failed and the OpsRequest fails normally;
  • added envtest coverage for both paths: recover-to-succeed and never-recovers-to-failed.

Validation on this machine:

git diff --check
go test ./pkg/operations -run TestAPIs -count=0

go test ./pkg/operations -run TestAPIs -count=1 is blocked locally because /usr/local/kubebuilder/bin/etcd is missing, so the envtest suite cannot start here.

weicao avatar Jun 01 '26 09:06 weicao

CI follow-up update: the first 03be32fb run failed because one test helper did not enable the new restart-only observation mode, so that test expected Running while the helper still used the terminal failed-progress path.

Fixed in head 9273bdfe00c4cc951bf23a303368c7ec8423b72e.

Local validation now passes with envtest assets:

git diff --check
KUBEBUILDER_ASSETS='/Users/wei/Library/Application Support/io.kubebuilder.envtest/k8s/1.26.1-darwin-arm64' go test ./pkg/operations -run TestAPIs -count=1

The existing failed-component test still expects Ops Failed; only the restart recoverable test explicitly enables the bounded observation path.

weicao avatar Jun 01 '26 09:06 weicao