Skip to content

api: add opt-in instance retention pruner - #1603

Open
mohammedadnan21 wants to merge 2 commits into
flatcar:mainfrom
mohammedadnan21:feat/instance-retention
Open

api: add opt-in instance retention pruner#1603
mohammedadnan21 wants to merge 2 commits into
flatcar:mainfrom
mohammedadnan21:feat/instance-retention

Conversation

@mohammedadnan21

@mohammedadnan21 mohammedadnan21 commented Aug 21, 2026

Copy link
Copy Markdown

Summary

  • Adds an opt-in background job that deletes instances whose newest last_check_for_updates (or created_ts if they never checked in) is older than -instance-retention. Default remains 0 (disabled), so existing deployments do not change on upgrade.
  • Dry-run (-instance-retention-dry-run) logs the would-delete count without removing rows. Live deletes run in batches; related instance_application, instance_status_history, event, and activity rows go with ON DELETE CASCADE.
  • Increments nebraska_instances_pruned_total for actual deletes. Operator notes are in docs/instance-retention.md.

Fixes #1585. Operators with node churn described the same gap in #352.

How to use

Retention stays off unless an operator sets a duration:

nebraska -instance-retention=2160h -instance-retention-dry-run

2160h is 90 days. Dry-run only logs candidates. Remove -instance-retention-dry-run to delete. Helm can pass the same flags via extraArgs.

Testing done

Against Postgres 17:

go test ./pkg/config ./pkg/api/runtime -run 'TestValidateInstanceRetention|TestPruneStaleInstances'

Those tests passed: stale vs fresh, dry-run, multi-app keep, batched deletes, cascade of status history, orphan created_ts prune, and config validation.

Dead machines stay in instance and related tables forever, which is the
growth operators hit when Kubernetes nodes churn. Keep the job off by
default, add a dry-run, and delete in batches so upgrades do not change
behaviour.

Signed-off-by: Mohammed Adnan <muhammedadnan50007@gmail.com>
A first enable against years of dead nodes must not drain the table in
one pass. Cap batches, re-check freshness at delete time, and keep
hourly logs quiet when nothing was removed.

Signed-off-by: Mohammed Adnan <muhammedadnan50007@gmail.com>
@mohammedadnan21
mohammedadnan21 marked this pull request as ready for review August 21, 2026 10:30
@mohammedadnan21
mohammedadnan21 requested a review from a team as a code owner August 21, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nebraska never deletes old instance data

1 participant