fix: fail Deployment tracking fast on ReplicaSet pod-create errors
Summary
The Deployment tracker now reports pod-create failures of the Deployment's new ReplicaSet (the ReplicaFailure/FailedCreate condition, e.g. exceeded quota) instead of waiting for the tracking timeout. Failures the rollout cannot recover from on its own fail the deploy immediately; the rest are charged against the allowed-failures budget.
This is a port of #399 by @Sharvash. When branch 1 was merged into main (#389) and deleted, GitHub closed #399 without merging it. His two commits are cherry-picked unchanged, with his authorship and sign-off. Our commits on top fix the quota classification and a lint error.
Closes #398
What
- Commits by @Sharvash (from #399):
fix: fail Deployment tracking on ReplicaSet pod-create errors: reads the durableReplicaFailurecondition of the new ReplicaSet rather than transient events, so failures that happened before tracking started are also seen. Only ReplicaSets controlled by the Deployment are considered.fix: handle ReplicaSet failure transitions consistently: waits for the initial ReplicaSet list before classifying, keeps informer events in order (unbuffered, cancellation-aware sends), handles ReplicaSet replacement, selector leave and re-entry, and deletion. Reports a failure once per ReplicaSet incarnation and re-arms it when the condition clears. Ignores a lagging condition once the Deployment is ready.
- Our commits:
fix: keep ReplicaSet quota failures counted while the rollout can release quota: see Quota classification below.chore: fix errorlint in deployment tracker test harness and document FailureMode field.fix: bound quota quantities parsed from a ReplicaSet failure message: theFailedCreatemessage can be written by anyone who can update the ReplicaSet status, and a quantity with a huge exponent kept the tracker busy for minutes. Only the bounded forms the quota admission plugin prints are parsed now; anything else keeps the failure counted.
Quota classification
The original heuristic reported a quota failure as fatal when the rollout could not scale an old ReplicaSet down at that moment. Several rollouts that do recover were therefore misclassified. One example: replicas: 3, maxSurge: 2, maxUnavailable: 0, a quota of 4 pods. The new ReplicaSet gets 1 of its 2 pods. Once that pod becomes available, an old pod is scaled down, quota is freed and the rollout continues. A quota failure is now fatal only if all of the following hold:
- Rollout projection. Assuming every existing pod of the new ReplicaSet becomes available, the Deployment controller still would not scale any old ReplicaSet down:
sum(old spec.replicas) + existing new pods <= replicas - maxUnavailable. The same formula asreconcileOldReplicaSets. - Fresh pod list. A quorum
list podsconfirms the projection: no pod of the rollout is terminating, no old ReplicaSet has surplus pods, and the new ReplicaSet is still missing pods. This check is needed because the status that brings the condition counts only the pods listed before the failed sync created any, andstatus.terminatingReplicasis feature-gated. - Quota status.
get resourcequotas/<name from the message>shows that the quota still has no room for the request. The ReplicaSet controller keepsFailedCreateacross its retry backoff, which can last minutes, so the condition can outlive the shortage. - Persistence. All of the above still hold after 10 seconds, re-evaluated from scratch. The checks read different objects at different moments, and quota usage drops only once the quota controller catches up with deleted pods.
If a check cannot be made (the list or get fails, for example because of RBAC, or the message does not parse), the failure stays counted, as on main.
Behaviour changes
- A Deployment whose new ReplicaSet cannot create pods is reported as failed. Before, tracking waited for the timeout.
- Fatal, failing the deploy regardless of
failures-allowed: an invalid pod spec (... is invalid:), or a quota failure confirmed as described above. A quota deadlock is reported about 10 seconds after it is observed. - Counted against the failures budget: everything else, such as webhook or RBAC rejections, recoverable quota failures, and quota failures that cannot be confirmed.
- A quota failure that clears within the confirmation period is not reported at all.
- Fatal, failing the deploy regardless of
- New public API in
pkg/tracker/deployment:type FailureMode,FailureModeCounted(the zero value, so existing code that builds aDeploymentStatuskeeps the old meaning) andFailureModeFatal, plus theDeploymentStatus.FailureModefield. It is meaningful only whenIsFailedis set. - dyntracker: a fatal Deployment failure marks the resource
Failed, which fails the readiness task immediately. - dyntracker fail modes (
statestore/readiness_task_state.go): withIgnoreAndContinueDeployProcess, a resource markedFaileddoes not fail the task. OnlyFailWholeDeployProcessImmediatelyandLegacyHopeUntilEndOfDeployProcessfail on it. Before this PR nothing setResourceStatusFailed, so the change affects only the new fatal failures: they respectwerf.io/fail-mode: IgnoreAndContinueDeployProcess. - Sticky failures are reported once. After an event-sourced failure, the Deployment tracker no longer re-stamps
IsFailed/FailedReasoninto every later status. Each failure is charged to the budget once, where before it was charged on every subsequent update. The StatefulSet and DaemonSet trackers still re-stamp. utils.FindNewReplicaSetonly considers ReplicaSets controlled by the Deployment.- RBAC: fast-failing on a quota deadlock needs
list pods(already required for tracking) andget resourcequotasin the namespace. The built-inview,editandadminroles include both. Without them, quota failures stay counted.
Why
#398: a deploy that hits exceeded quota (or any other pod-create error) hangs until the tracking timeout, and the reason only shows up in ReplicaSet events, which the tracker did not watch.
Testing
go test ./...andgo test -raceon the touched packages pass.task lintreports 0 issues.- Unit tests for every classification case. Each counted case fails with the corresponding check disabled.
- kind (Kubernetes v1.36.1) with a
ResourceQuotaon pods, using the Deployment from the example above, tracked throughdyntrackerthe way nelm does it:- quota 3 (deadlock):
mainwaits for the timeout. This branch fails with theFailedCreate ... exceeded quotadiagnostic about 10 seconds after the failure appears. - quota 4 (recoverable): #399 as it was failed after 2s. This branch keeps waiting, and the rollout completes once the ReplicaSet controller retries. That took several minutes because of its retry backoff.
- Tracking started in the middle of that backoff, after quota had been freed but with the condition still set: counted, and the rollout completes.
- quota 3 (deadlock):
Merging
Please merge with a merge commit or a rebase, not a squash, so that @Sharvash stays the author of his commits.