Ramesh Kuppili
Ramesh Kuppili

Reputation: 31

When will a kube object have more than one ownerReferences

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

Answers (3)

Eron Wright
Eron Wright

Reputation: 1060

To expand on this, the owner refs are used for two scenarios:

  1. garbage collection
  2. adoption (e.g. of existing pods into a deployment based on a selector)

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

Rishi Anand
Rishi Anand

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

Wytrzymały Wiktor
Wytrzymały Wiktor

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

Related Questions