Skip to content

feat: idle Knative Service cleanup based on last-scaled activity - #26

Open
williamsena-vtex wants to merge 10 commits into
mainfrom
worktree-idle-knative-cleanup
Open

feat: idle Knative Service cleanup based on last-scaled activity#26
williamsena-vtex wants to merge 10 commits into
mainfrom
worktree-idle-knative-cleanup

Conversation

@williamsena-vtex

Copy link
Copy Markdown
Contributor

Summary

  • Adds a new, independent IdleKnativeCleanupReconciler that deletes Knative Services declaring autoscaling.knative.dev/min-scale: "0" once all their Deployments have stayed at 0 replicas past a configurable threshold, tracked via a controller-owned cleaner.vtex.io/idle-since annotation (no reliable native "last replicas changed" field exists on Deployment or Knative objects — see design doc).
  • Fully opt-in per cluster via env vars, no rebuild required: IDLE_KNATIVE_CLEANUP_ENABLED (default false) and IDLE_KNATIVE_CLEANUP_THRESHOLD (default 12h).
  • Per-object opt-out via cleaner.vtex.io/exclude: "true" annotation on the Service.
  • Independent of the existing ConditionalTTL CRD/CEL machinery — no changes to api/v1alpha1/ or custom_cel/.

Design & Plan

  • Design spec: docs/superpowers/specs/2026-09-01-idle-knative-cleanup-design.md (local, gitignored)
  • Implementation plan: docs/superpowers/plans/2026-09-01-idle-knative-cleanup.md (local, gitignored)

Test plan

  • controllers/idle_knative_cleanup_helpers_test.go — table-driven unit tests for candidate-detection helpers (no envtest)
  • controllers/idle_knative_cleanup_controller_test.go — envtest/Ginkgo coverage: marks idle-since, deletes past threshold, resets on reactivation, respects exclude annotation, ignores non-candidates
  • make fmt vet test passes (full suite, including pre-existing ConditionalTTL suite — no regressions, coverage 73.2% → 77.3%)
  • make manifests regenerated config/rbac/role.yaml with the new serving.knative.dev/services and apps/deployments rules

🤖 Generated with Claude Code

williamsena-vtex and others added 5 commits September 2, 2026 09:25
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vtex-pr-sentinel

Copy link
Copy Markdown

🛡️ SDD Check — action required

I couldn't detect an SDD in this PR. Please check one option below (requires write access to the repo):

  • SDD lives in another PR — paste the SDD PR URL here:
  • This PR doesn't need an SDD
  • SDD applies, but I'm not adopting it in this PR

@williamsena-vtex williamsena-vtex self-assigned this Sep 2, 2026
williamsena-vtex and others added 2 commits September 4, 2026 13:52
A cluster runs cleanup by either ConditionalTTL's creation-timestamp
TTL or Knative idle detection, never both at once.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
williamsena-vtex and others added 3 commits September 4, 2026 17:47
Both are local working docs for the brainstorming/writing-plans
workflow, not artifacts meant to live in the repo history.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
IDLE_KNATIVE_CLEANUP_ENABLED only turns the idle-cleanup controller on
or off; ConditionalTTL's creation-timestamp TTL cleanup always runs,
same as before this feature was added.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Without these, the generated Helm chart had no way to set
IDLE_KNATIVE_CLEANUP_ENABLED/_THRESHOLD at install/upgrade time -
required to actually turn the feature on in a cluster.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

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.

1 participant