Files
obsidian-sympozium/08-Słownik-K8s/ownerReference.md
2026-03-25 00:05:57 +01:00

67 lines
2.0 KiB
Markdown

# ownerReference
#kubernetes #lifecycle #garbage-collection #słownik
## Co to jest?
**ownerReference** to metadata na zasobie Kubernetes wskazująca na jego "właściciela". Gdy właściciel jest usunięty, Kubernetes **automatycznie garbage-collectuje** zasoby-dzieci.
## Jak działa?
```yaml
# Child resource (np. Job)
metadata:
ownerReferences:
- apiVersion: sympozium.ai/v1alpha1
kind: AgentRun
name: my-run-001
uid: abc-123
controller: true
blockOwnerDeletion: true
```
```
Usunięcie AgentRun → K8s GC → Usunięcie Job → Usunięcie Pod
```
## Cascade deletion
| Typ | Zachowanie |
|-----|------------|
| **Foreground** | Owner czeka na usunięcie children |
| **Background** | Owner usunięty natychmiast, children async |
| **Orphan** | Children nie są usuwane (osierocone) |
## Ograniczenia
- ownerReference działa **tylko w tym samym namespace**
- Cluster-scoped zasoby (ClusterRole) **nie mogą** mieć ownerRef na namespace-scoped (AgentRun)
- Dlatego Sympozium używa label-based cleanup dla cluster RBAC
## Użycie w Sympozium
### Automatyczne (ownerRef)
```
PersonaPack → owns → SympoziumInstance → owns → Channel Deployment
→ owns → Memory ConfigMap
→ owns → AgentRun → owns → Job
→ owns → Role
→ owns → RoleBinding
```
Usunięcie PersonaPack = kaskadowe usunięcie CAŁEGO drzewa.
### Manualne (label-based, bo cross-namespace)
```
ClusterRole (cluster-scoped) ← label: sympozium.ai/agentrun: my-run
ClusterRoleBinding ← label: sympozium.ai/agentrun: my-run
Controller czyści po labelach w reconcileCompleted()
```
Więcej: [[Finalizer]] | [[Efemeryczny RBAC per-run]] | [[PersonaPacks - zespoły agentów]]
---
Powiązane: [[Finalizer]] | [[Controller i Reconciler]] | [[CRD - Custom Resource Definition]]