Author: gmarek@ Last edit: 2016-05-11 Status: raw
Approvers:
Table of Contents
Main goal of ControllerReference
effort is to solve a problem of overlapping controllers that fight over some resources (e.g. ReplicaSets
fighting with ReplicationControllers
over Pods
), which cause serious problems such as exploding memory of Controller Manager.
We don’t want to have (just) an in-memory solution, as we don’t want a Controller Manager crash to cause massive changes in object ownership in the system. I.e. we need to persist the information about "owning controller".
Secondary goal of this effort is to improve performance of various controllers and schedulers, by removing the need for expensive lookup for all matching "controllers".
Cascading deletion is not a goal of this effort. Cascading deletion will use ownerReferences
, which is a separate effort.
ControllerRef
will extend OwnerReference
and reuse machinery written for it (GarbageCollector, adoption/orphaning logic).
There will be a new API field in the OwnerReference
in which we will store an information if given owner is a managing controller:
OwnerReference {
…
Controller bool
…
}
From now on by ControllerRef
we mean an OwnerReference
with Controller=true
.
Most controllers (all that manage collections of things defined by label selector) will have slightly changed semantics: currently controller owns an object if its selector matches object’s labels and if it doesn't notice an older controller of the same kind that also matches the object's labels, but after introduction of ControllerReference
a controller will own an object iff selector matches labels and the OwnerReference
with Controller=true
points to it.
If the owner's selector or owned object's labels change, the owning controller will be responsible for orphaning (clearing Controller
field in the OwnerReference
and/or deleting OwnerReference
altogether) objects, after which adoption procedure (setting Controller
field in one of OwnerReferencec
and/or adding new OwnerReferences
) might occur, if another controller has a selector matching.
For debugging purposes we want to add an adoptionTime
annotation prefixed with kubernetes.io/
which will keep the time of last controller ownership transfer.
Because ControllerRef
will be a part of OwnerReference
effort it will have the same upgrade/downgrade procedures.
Because ControllerRef
will be a part of OwnerReference
effort it will have the same orphaning/adoption procedures.
Controllers will orphan objects they own in two cases:
Orphaning=true
(executed by the GarbageCollector)We will need a secondary orphaning mechanism in case of unclean controller deletion:
ControllerRef
from objects that no longer points to existing controllersController will adopt (set Controller
field in the OwnerReference
that points to it) an object whose labels match its selector iff:
OwnerReferences
with Controller
set to true in OwnerReferences
arrayDeletionTimestamp
is not set
andDeletionTimestamp
set.By design there are possible races during adoption if multiple controllers can own a given object.
To prevent re-adoption of an object during deletion the DeletionTimestamp
will be set when deletion is starting. When a controller has a non-nil DeletionTimestamp
it won’t take any actions except updating its Status
(in particular it won’t adopt any objects).
Controller
,OwnerReference
adoption procedure to set a Controller
field in one of the owners,ControllerRef
.Necessary related work:
OwnerReferences
are correctly added/deleted,DeletionTimestamps
is set.ControllerRef
in the ObjectMeta.
ControllerRef
and OwnerReferences
when it comes to deletion/adoption.