Skip to content

Feat/mpr 202 owned deletion - #291

Merged
yasaurabh merged 5 commits into
ai-agent-runtimefrom
feat/MPR-202-owned-deletion
Nov 26, 2026
Merged

yasaurabh merged 5 commits into
ai-agent-runtimefrom
feat/MPR-202-owned-deletion

Conversation

@yasaurabh

@yasaurabh yasaurabh commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Title: feat(agent-runtime): delete only operator-owned objects and keep customer data (MPR-202)

Base: ai-agent-runtime Head: feat/MPR-202-owned-deletion

Summary

Deleting an AgentRuntime feature now removes only the objects the operator created for it, through owner references and garbage collection. Customer data stays: the PostgreSQL database and checkpoint records, referenced Secrets, user-named ServiceAccounts and TLS Secrets, PVCs, model artifacts and shared infrastructure. Both profiles follow the same rules.

  • Jira: MPR-202, under epic MPR-182.
  • Design source: Agent-Runtime / AI-Tier Integration ERD, FR-17 and §14.4.3 ("Deleting the feature removes only operator-owned … objects … Customer-managed PostgreSQL data, checkpoint records, referenced Secrets, model artifacts, and shared AI Tier infrastructure remain").
  • Runbook for MPR-216: docs/agent-runtime/ownership-and-deletion.md. Validation record: docs/agent-runtime/mpr-202-validation.md. Captured cluster runs: docs/agent-runtime/validation/mpr-202-cluster.txt.

What was wrong

Each of these was reproduced on a real API server before the fix:

  • A customer ServiceAccount could be deleted. A ServiceAccount named in features[].serviceAccountName was adopted (given the AIService as controller), so garbage collection would delete it with the AIService.
  • Same-named objects were overwritten. An existing ConfigMap, Certificate, Service, HPA or ServiceMonitor under a name the feature uses was accepted silently: its content replaced, no owner reference added, and left behind as an orphan.
  • The mTLS Secret was left behind. cert-manager writes <name>-tls without an owner, so it outlived the AIService.
  • The finalizer handlers were dead code. No code adds the aiservice-protect / aiplatform-protect finalizers, but their handlers remained. The platform's handler deleted children itself and held the platform until they were gone.
  • Feature pruning matched by owner name, not UID. It could delete an AIService left by an earlier platform with the same name.
  • The operator could not record events. Its ClusterRole had no events rule, so every event on an AIService or AIPlatform was rejected ("events is forbidden"), InvalidSpec included.

What it does

  • Ownership rule (common.ClaimOrRefuse), applied to the ServiceAccount, ConfigMap, Certificate, schema Job, Deployment, Service, HPA and ServiceMonitor:
    • every object is created with the AIService as controller;
    • an existing object the AIService doesn't control (by UID) is never adopted, rewritten or deleted. The stage fails with reason OwnershipConflict, naming the object, and a Warning event is recorded;
    • nothing is ever deleted by label.
  • User-named ServiceAccount: customer-managed. Used if it exists, created without an owner if not; an owner reference left by an earlier build is removed.
  • mTLS Secret: the operator-generated <name>-tls gets a non-controller owner reference once cert-manager issues it for this Certificate, so it's removed with the AIService. A Secret named in mtls.secretName is never owned.
  • No finalizer: the dead handlers are removed. An object still carrying a 2025-08 finalizer is released at once, so nothing can hold a deletion.
  • Pruning of removed features matches the AIService by UID.
  • RBAC: create/patch on core events in the generated and Helm ClusterRoles. The test that keeps the two identical now also requires this rule.
  • SAIA is unchanged. The shared ServiceAccount/Certificate helpers apply the new rule only when asked (RefuseUnowned), so SAIA keeps adopting as before, with a test pinning that. Neither the ERD nor the story covers SAIA ownership.

Commits

  1. fix(rbac): let the operator record events on AIServices and AIPlatforms
  2. feat(agent-runtime): delete only operator-owned objects and keep customer data
  3. docs(agent-runtime): ownership inventory, deletion runbook and validation record

Testing done

Check Result
Unit and envtest ownership envtest suite (both profiles, same-named customer objects, partial install, injected API failure, idempotency, TLS Secret rules); helper, platform and controller tests
Mutation checks 30 deliberate breakages of the new rules, each caught; 3 more of the events RBAC test, each caught
Module go build, go vet; all 24 non-e2e packages pass; race detector clean on the changed packages
Independent review no correctness bug; its five minor points were addressed

Cluster (fullfeature-dev, 2026-11-24, retested 2026-11-25 on 9d4a0cd with PR #290):

Scenario Result
cpuOnly feature removal only the runtime's owned objects (and SLIM's) removed. The customer ServiceAccount, a similarly named ConfigMap, the checkpoint and pull Secrets and PostgreSQL kept at their resourceVersions; marker checkpoint rows read back identical
Same-named customer ServiceAccount / ConfigMap OwnershipConflict condition and Warning event, object unchanged, recovered after removal
Partial install, API failure (HPA create permission removed) only owned objects, nothing deleted, recovered when restored
fullfeature runtimes with mTLS operator-generated TLS Secret owned and removed; user-named Secret and Issuer kept
2025-08 finalizers, operator killed mid-install, platform deletion deleted within 2 s; no unowned object; customer data kept
Live platform Ready throughout; no events rejected; restored identically afterwards

Not covered

  • PodDisruptionBudget and NetworkPolicy don't exist yet (MPR-205). Built with the same helper, they'll follow the same rule.
  • SLIM and SAIA's other objects still use the old adopt pattern. That's outside this story; a separate ticket if wanted.
  • Pre-existing test-suite flake: a data race appears under -race with some spec orders, on the base too, because older specs write the shared client-go scheme. The new specs use a private scheme.

Found along the way

yasaurabh and others added 3 commits November 25, 2026 12:10
The ClusterRole had no rule for core events; the only grant was in the
leader-election Role, in the operator's own namespace. Every event the
recorders emitted on an AIService or AIPlatform elsewhere was rejected
("events is forbidden"), so InvalidSpec and the other warnings never
appeared. Add create/patch on core events to the generated and the Helm
ClusterRole, and require the rule in the test that keeps them identical.

Verified on fullfeature-dev: no rejected event in a full test run, and the
warnings appear on the AIService with the operator's own ClusterRole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omer data (MPR-202)

Ownership rule for every object the AgentRuntime feature creates:
- created with the AIService as controller, so garbage collection removes it
  and an interrupted reconcile leaves only owned objects;
- an existing object under a feature name that this AIService (by UID) does
  not control is never adopted, rewritten or deleted: the stage fails with
  reason OwnershipConflict naming it (common.ClaimOrRefuse). The schema Job's
  occupied-name case reports the same reason;
- a ServiceAccount named in features[].serviceAccountName is customer-managed:
  used if it exists, created without an owner if not, and an owner reference
  left by an earlier build is removed;
- the operator-generated mTLS Secret <name>-tls gets a non-controller owner
  reference once cert-manager issues it for this Certificate; a user-named
  secret is never owned.

The shared ServiceAccount and Certificate helpers apply the rule only when
asked (RefuseUnowned), so SAIA keeps adopting as before.

No finalizer: the unused aiservice-protect/aiplatform-protect cleanup
handlers are removed, and an object still carrying one from 2025-08 builds is
released at once, so deletion can never be held. The platform prunes a removed
feature's AIService only when it controls it by UID.

Tests: envtest ownership suite (both profiles, same-named objects, partial
install, injected API failure, idempotency), helper and controller tests; 30
mutations caught. Cluster-tested on fullfeature-dev, including checkpoint
readback after deletion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion record (MPR-202)

ownership-and-deletion.md: the ownership rule, the operator-owned and
customer-managed inventories, what remains after each kind of deletion, how to
check a deletion, troubleshooting OwnershipConflict and the upgrade note.
mpr-202-validation.md and validation/mpr-202-cluster.txt: criteria, tests and
the captured fullfeature-dev runs, including the root cause of the Deployment
churn fixed by PR #290 (introduced by 955dd11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T09:54:25.854332Z 8dfb082 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@yasaurabh yasaurabh self-assigned this Nov 25, 2026
@yasaurabh
yasaurabh requested a review from kc-splunk November 25, 2026 06:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85da066bd6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/ai/features/agentruntime/impl.go Outdated
Comment on lines +456 to +458
if err != nil || ai.Spec.MTLS.SecretName != "" {
// A Secret the user named stays theirs: it is not removed with the AIService.
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detach the TLS Secret when it becomes explicitly user-named

If a runtime initially leaves mtls.secretName unset, ownIssuedSecret adds an AIService owner reference to <svc>-tls. If the user subsequently sets mtls.secretName to that same Secret to retain or share it, this early return leaves the existing owner reference intact. Deleting the AIService therefore still garbage-collects the now explicitly referenced Secret, contrary to the documented preservation behavior; before this change, the operator did not add that reference. Remove this AIService's owner reference when the Secret becomes explicitly user-named, analogous to the customer-managed ServiceAccount handling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@codex review

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 8dfb082690

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

yasaurabh and others added 2 commits November 25, 2026 14:12
…tName (MPR-202)

Address PR #291 review: a runtime that started without mtls.secretName gets
its operator-generated <svc>-tls Secret claimed with an owner reference. If the
user then names that same Secret in mtls.secretName to keep it, the reference
stayed, so deleting the AIService still removed the Secret, contrary to the
documented rule that a user-named Secret is never removed. The operator now
removes its own owner reference (by UID) from a user-named Secret, keeping any
other, with an optimistic-lock patch.

Envtest reproduces the sequence (claimed, then named, then released and
idempotent); 32 mutations caught; 24 packages pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elease (MPR-202)

Section 13 of the fullfeature-dev record: the 6b88171 build claims the
operator-generated TLS Secret, releases it within 3 s once mtls.secretName
names it, and the Secret survives the AIService's deletion. Cluster restored
and verified identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yasaurabh
yasaurabh merged commit 9151726 into ai-agent-runtime Nov 26, 2026
1 check passed
@yasaurabh
yasaurabh deleted the feat/MPR-202-owned-deletion branch November 26, 2026 05:31
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.

2 participants