Skip to content

✨ Sweep resources orphaned by deleted runs - #217

Merged
djzager merged 2 commits into
konveyor:mainfrom
ibolton336:feature/run-orphan-cleanup
Sep 4, 2026
Merged

✨ Sweep resources orphaned by deleted runs#217
djzager merged 2 commits into
konveyor:mainfrom
ibolton336:feature/run-orphan-cleanup

Conversation

@ibolton336

Copy link
Copy Markdown
Member

Summary

  • audit and test the existing AgentRun → Sandbox/Secret/ConfigMap and AgentWorkflowRun → stage AgentRun ownership chain
  • sweep labeled Sandboxes, Pods, ConfigMaps, Secrets, and stage AgentRuns when their owning run is gone
  • confirm cache misses against the API server and preserve resources controlled by another owner
  • add the required cleanup watches, RBAC, and changelog fragment

Testing

  • go vet ./...
  • KUBEBUILDER_ASSETS=bin/k8s/1.36.2-linux-arm64 go test $(go list ./... | grep -v /e2e) -coverprofile cover.out
  • YQ=bin/yq hack/changelog.sh validate

Fixes #200

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 455d0532-d317-4ae7-b3bd-837e203b5831


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ibolton336
ibolton336 force-pushed the feature/run-orphan-cleanup branch from 51048a6 to df47cbf Compare September 3, 2026 15:16

@djzager djzager left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full change against the surrounding controller code — nice work. The owner-reference-first / label-sweep-as-recovery framing is sound, the apiReader re-check before deleting correctly guards against unordered cross-type informer events, and mayDeleteForMissingOwner properly refuses to touch objects controlled by another controller. I confirmed all swept types (Sandbox, params + inline-skill ConfigMaps, ACP Secret) carry both app.kubernetes.io/managed-by and konveyor.io/agentrun at creation, so the sweep selector actually finds them, and that apiReader is wired on both reconcilers.

A few non-blocking notes:

1. Test gap: the pod deletion guard's production path isn't exercised.
In agentrun_controller_test.go, the swept Pod is created ownerless, so it deletes via the ownerless branch of mayDeleteForMissingOwner. In production the pod is owned by the Sandbox, so deletion goes through the apiVersion == "agents.x-k8s.io/v1beta1" && Kind == "Sandbox" && Name == run.Name branch — which has no coverage. If any of those strings drift, pods would silently stop being swept and the tests would stay green. Worth a case with a pod that has a Sandbox controller owner reference.

2. sandboxAPIVersion/sandboxKind are hardcoded, unlike the AgentRun side.
run_cleanup.go derives the AgentRun owner apiVersion from konveyoriov1alpha1.GroupVersion.String() but hardcodes sandboxAPIVersion = "agents.x-k8s.io/v1beta1". It matches agent-sandbox v0.5.0 today, but a dependency bump would silently break the pod guard in (1) with no compile error. Deriving it from sandboxv1beta1.GroupVersion.String() keeps the two in lockstep.

3. Minor: categorization. :sparkles: + kind: enhancement is consistent with issue #200's label, but the behavior (stop leaking dangling Sandboxes/Pods/ConfigMaps/Secrets) reads like a bugfix. Purely a labeling judgment call — take it or leave it.

Nothing here blocks merge from my side.

Signed-off-by: Ian Bolton <ibolton@redhat.com>
Signed-off-by: ibolton336 <ibolton@redhat.com>
@ibolton336
ibolton336 force-pushed the feature/run-orphan-cleanup branch from 2c189dc to 07b10d4 Compare September 4, 2026 18:14
@djzager
djzager merged commit ae7a72c into konveyor:main Sep 4, 2026
33 checks passed
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.

Owner-reference cascade + orphan sweep so run deletion reaps sandboxes, pods, and per-run config

2 participants