feat(defrag): EtcdDefragPolicy — scheduled EtcdDefrag runs - #363
Open
Andrey Kolkov (androndo) wants to merge 2 commits into
Open
feat(defrag): EtcdDefragPolicy — scheduled EtcdDefrag runs#363Andrey Kolkov (androndo) wants to merge 2 commits into
Andrey Kolkov (androndo) wants to merge 2 commits into
Conversation
Adds a CronJob-style `EtcdDefragPolicy` so the operator drives recurring defragmentation itself, instead of relying on an external CronJob to create `EtcdDefrag` objects (the follow-up flagged as "planned" in the EtcdDefrag docs). The policy reconciler stamps out `EtcdDefrag` runs on a five-field cron schedule (evaluated in UTC; a CRON_TZ prefix is honoured). Each stamped run is owned by the policy (cascades on delete) and labelled with the policy name, and carries the policy's `rule` and `ttlSecondsAfterFinished` — the run then follows all of EtcdDefrag's existing safety rules (per-cluster serialization, health gate, followers-before-leader), so the policy only triggers runs and never defragments directly. Spec: `schedule`, `clusterRef`, `rule`, `ttlSecondsAfterFinished`, `suspend`, `concurrencyPolicy` (Forbid default / Allow), `startingDeadlineSeconds`, and `historyLimit`. Status: `lastScheduleTime` (anchors the next tick so one is never acted on twice), `lastSuccessfulTime`, `active`, and an `Active` condition carrying Suspended / InvalidSchedule reasons. A long backlog after downtime is collapsed into a single run rather than replayed. Adds the API type + generated CRD/deepcopy/RBAC, the controller (wired in main.go, watches its owned EtcdDefrags), robfig/cron/v3, unit + controller tests (schedule parsing/next-tick math, stamp-when-due, not-due, suspend, invalid schedule, Forbid/Allow concurrency, history GC), and docs. Stacked on the EtcdDefrag controller PR. Refs #221. Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrey Kolkov <androndo@gmail.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The controller skips a tick older than StartingDeadlineSeconds — emitting MissedSchedule and consuming the tick without stamping a run — but the case was untested. Add a missed-deadline case (tick past the window: no run, tick still consumed) and a within-deadline mirror (run stamped normally). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrey Kolkov <androndo@gmail.com>
Andrey Kolkov (androndo)
marked this pull request as ready for review
August 20, 2026 08:42
Andrey Kolkov (androndo)
requested review from
Timofei Larkin (lllamnyp) and
Kirill Ilin (sircthulhu)
as code owners
August 20, 2026 08:42
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.
Adds a CronJob-style
EtcdDefragPolicyso the operator drives recurring defragmentation itself, instead of relying on an externalCronJob/GitOps cron to createEtcdDefragobjects. This is the follow-up flagged as planned in theEtcdDefragdocs.Stacked on #361 (the
EtcdDefragcontroller) — base isfeat/defrag-and-capacity-metrics. The diff here is the policy kind + its controller; the runs it stamps are theEtcdDefragfrom #361. Merge #361 first; GitHub will retarget this tomain.What it does
Reconciles an
EtcdDefragPolicyas a scheduler that stamps outEtcdDefragruns on a cron cadence:CRON_TZ=<zone>prefix is honoured). On each due tick it creates oneEtcdDefrag, owned by the policy (cascades on delete) and labelled with the policy name.ruleandttlSecondsAfterFinished, then follows all of feat(defrag): EtcdDefrag controller #361's safety rules — per-cluster serialization, the health gate (incl. NOSPACE handling), followers-before-leader. The policy only triggers; it never defragments directly.concurrencyPolicy—Forbid(default: skip a tick while a stamped run is still active) orAllow(stamp anyway;EtcdDefrag's own serialization queues it).suspendpauses stamping (missed ticks are not backfilled);startingDeadlineSecondsskips a tick already older than the deadline (e.g. after downtime) rather than starting it late;historyLimittrims retained finished runs (the oldest go first), complementing per-run TTL.status.lastScheduleTimeanchors the next tick (so a tick is never acted on twice);status.lastSuccessfulTimerecords the lastComplete;status.activelists in-flight runs; anActivecondition carriesSuspended/InvalidSchedulereasons.Adds the API type + generated CRD/deepcopy/RBAC; the controller (wired in
main.go, watches its ownedEtcdDefrags);github.com/robfig/cron/v3(what k8s CronJob uses). No changes toEtcdCluster/EtcdDefragbehavior.Usage
Tests
lastScheduleTimeset); not-due requeues without stamping;suspendreportsSuspended; an unparseable schedule reportsInvalidSchedule;Forbidskips while a run is active;Allowstamps concurrently;historyLimitGCs the oldest finished runs.go build/go vet/go test ./.../gofmtgreen; CRD/RBAC/deepcopy regenerated (codegen-drift clean).Refs #221.
🤖 Generated with Claude Code