Reputation: 31
When a kubernetes object has parent objects, it is mentioned under "ownerReferences". For example when i printed a pod spec in yaml format, i see ownerReferences mentioned as follows:
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: StatefulSet
name: statefuleset-name
uid: <uuid>
....
I see that ownerReferences is a list. Does anyone know when the ownerReferences will have more than one entries. I am not able to imagine a object having more than one owner.
Upvotes: 2
Views: 3126
Reputation: 1060
To expand on this, the owner refs are used for two scenarios:
Garbage collection works in a uniform way; the object is a candidate after ALL owners are deleted.
The controller
field was added later to support scenario (2).
Upvotes: 1
Reputation: 300
You can have your own use-case and respective CRDs and there can be a requirement of associating an object with multiple owners.
Just taking a very basic example, consider there is a School, with multiple teachers and multiple students, if all 3 are different CRDs then the student may have OwnerReference of kind School
with the school name and OwnerReference of kind Teacher
with teacher name.
By the way, cluster-api uses multiple ownerReferences in few of it's CRDs.
Upvotes: 1
Reputation: 13888
If I understand you correctly it is possible in some circumstances.
In this blog you can see an example of multiple ownerReferences
. The blog explains garbage collection in K8s and shows that Multiple ownerReferences are possible:
Yes, you heard that right, now postgres-namespace can be owned by more than one database object.
I hope it helps.
Upvotes: 2