feat: implement replica_rightsizing, rightsize_pvc, volume_delete agent_task remediations - #479
Merged
Merged
Conversation
…k dispatch The agent_task poller dispatches through HandleTrusted, which wraps every handler in the 180s TaskTimeout. The upcoming rightsize_pvc downsize migration copies volume data via a mover pod and routinely exceeds that, so: - dispatch.Config gains LongTaskTimeout + LongActions; HandleTrusted applies the long ceiling only to those actions. The WS Handle path is untouched (no long action reaches it). 0 disables the override. - The poller runs LongActions on a detached goroutine (context.WithoutCancel) so a multi-minute task neither stalls the queue drain nor gets cancelled by the next poll tick. The collector already flips the row to PROCESSING on GET, so it is not re-handed while running.
…iations Adds the three agent_task remediation actions the api-server enqueues but the Go agent did not yet implement (the poller would reply "action not registered"): - replica_rightsizing: scale Deployment/StatefulSet/Rollout via the dynamic client; replica_count coerced from JSON number or numeric string (both wire forms the server sends). - rightsize_pvc: RightsizePVC routes by provisioned capacity. Expansion patches spec.resources.requests.storage after checking allowVolumeExpansion. Downsize can't shrink a PV in place, so it runs a copy-migration (faithful port of the legacy robusta path): Deployment = new PVC -> copy -> repoint -> delete original (point of no return = repoint); StatefulSet = name-preserving double copy with PV reclaim flipped to Retain before the original PVC is deleted. Data is moved by a transient ubuntu mover pod (cp -a) exec'd over SPDY, with config-parity verification and stage-aware rollback that leaves data on two copies after the point of no return. - volume_delete: delete an unused PV (payload name is the cluster-scoped PV) and its bound PVC via claimRef; both deletes are 404-tolerant. All three are delivered via the trusted agent_task poller and stay OUT of the light-action allowlist (same posture as rightsizing_resource).
…v CLI - main.go: wire mut.SetExec (SPDY mover-pod exec for downsize), register rightsize_pvc in dispatch+poller LongActions, and set LongTaskTimeout (50m default, env LONG_TASK_TIMEOUT_SECONDS) under the server's 60m PROCESSING reap window. - pkg/mutate/live_test.go (build tag `live`): asserted end-to-end tests against a real cluster — expand, replica scale, downsize-with-data-survival, and volume_delete. Excluded from normal builds; sizes/SC env-tunable. Verified green on GKE (incl. data preserved across the downsize migration). - cmd/actionctl: small dev CLI to invoke a single remediation handler against the cluster without the relay/backend, for ad-hoc testing.
There was a problem hiding this comment.
Code Review
This pull request introduces local development tools and implements agent remediation handlers for scaling workloads (replica_rightsizing), resizing PVCs (rightsize_pvc), and deleting volumes (volume_delete). It also updates the task poller to run long-running tasks asynchronously. The feedback highlights critical reliability issues: retrying workload scaling can overwrite the original replica count; retrying deployment repointing can fail if already updated; detaching the context prevents graceful cleanup on agent shutdown; and hardcoded copy timeouts and mover images limit scalability and enterprise compatibility.
From PR #479 review: - scaleWorkloadTyped: capture the original replica count only on the first read, so a conflict-retry that re-Gets an already-scaled object can't clobber `old` with 0 (which would leave the workload restored to 0). - repointDeploymentPVC: treat "volume already points to newPVC" as success — a prior Update may apply server-side before the client sees a conflict, and the retry must not hard-fail the migration. - copyData: bound the copy by the remaining LongTaskTimeout budget (copyTimeout) instead of a fixed `timeout 300`, so large volumes aren't cut off at 5m. - mover image: configurable via MOVER_IMAGE (fallback "ubuntu") for clusters that can't pull from Docker Hub. - poller: keep the agent context for long actions instead of detaching with WithoutCancel, so a graceful shutdown propagates cancellation and the migration's rollback defers run within the termination grace.
Contributor
|
📦 Image Tags Updated |
RamanKharchee
previously approved these changes
Jun 16, 2026
- actionctl: call cancel() explicitly before os.Exit (gocritic exitAfterDefer); declare params with var to drop the unused initializer (staticcheck SA4006). - poller_test: tagged switch on r.Method (staticcheck QF1002).
Contributor
|
📦 Image Tags Updated |
RamanKharchee
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The api-server enqueues several remediation/apply actions onto the
agent_taskqueue that the Go agent's poller dispatches byaction_name. Three were unimplemented — the poller replied "action not registered", so applying these recommendations failed:replica_rightsizing— scale-to-zero of abandoned workloads + event-resolutionincrease_replicasrightsize_pvc— PVC resize recommendations (expand and downsize)volume_delete— delete unused PersistentVolumesThis PR implements all three (ports the legacy robusta behavior), plus the execution-model changes the long-running downsize migration needs.
Changes
Handlers (
pkg/mutate)replica_rightsizing: scale Deployment/StatefulSet/Rollout via the dynamic client;replica_countcoerced from JSON number or numeric string (both wire forms).rightsize_pvc: routes by provisioned capacity. Expansion patches the storage request after checkingallowVolumeExpansion. Downsize runs a copy-migration — Deployment (new PVC → copy → repoint → delete original) and StatefulSet (name-preserving double copy with PV reclaim→Retain before the destructive delete). Data is moved by a transientubuntumover pod (cp -a) exec'd over SPDY, with config-parity verification and stage-aware rollback that keeps two data copies past the point of no return.volume_delete: deletes the PV (payloadnameis the cluster-scoped PV) and its bound PVC viaclaimRef; 404-tolerant.agent_taskpoller and stay out of the light-action allowlist (same posture asrightsizing_resource).Execution model (
pkg/dispatch,pkg/tasks)LongTaskTimeoutso the migration isn't killed by the 180s dispatch cap. Default 50m (envLONG_TASK_TIMEOUT_SECONDS), kept under the server's 60mPROCESSING→TIMEOUTreap.Tooling / tests
pkg/mutate/live_test.go(//go:build live): asserted end-to-end tests against a real cluster — expand, replica scale, downsize-with-data-survival, volume_delete. Excluded from normal builds; sizes/SC env-tunable.cmd/actionctl: small dev CLI to invoke a single handler against the cluster without the relay/backend.Testing
TestLive*pass, including data preserved across the full downsize migration (mover pod copy → repoint → original deleted → token read back from the new PVC).Notes
timeout 300; integrity check iscp -aexit +COPY_SUCCESSmarker (no checksum) — both inherited from the legacy action.