kopf.adopt How to set controller to False ? - multiple entries in ownerreferences section
Hi, I am getting following error when i try to add multiple entries to ownerreference section of custom resource using kopf.adopt function. I am doing kopf.adopt , then patch_namespaced_custom_object (update). kopf.adopt , by default setting 'controller': True,, i want to make it False
Error:
Only one reference can have Controller set to true. Found "true" in references for bun-test2 and bun-test3","field":"metadata.ownerReferences"}]},"code":422}
is there any way to add entries to ownerReferences with 'controller': False, ??
{'ownerReferences': [{'controller': False, 'blockOwnerDeletion': True, 'apiVersion': 'kopf.dev/v1', 'kind': 'KopfExample', 'name': 'kopf-example-1', 'uid': '6b931859-5d50-4b5c-956b-ea2fed0d1058'}]}},
https://github.com/nolar/kopf/blob/f20df84d4b1ee50aa7249cf6066826e5e2b31cf2/docs/hierarchies.rst
Usually, the object is a plain dict. It can be modified.
kopf.adopt(...)
for ref in data['metadata']['ownerReferences']:
ref['controller'] = False
kopf.adopt() is supposed to take full ownership of the object, and semantically, there can be only one owner.
Alternatively, you can add your own ownerReferences items with a fully controlled structure and content — without kopf.adopt(). Kopf does not do anything other than just injecting a little dict into that field. The current owner can be identified from the kwargs name, namespace, uid, and resource (owner refs need resource.kind and f"{resource.group}/{resource.version}" probably): https://kopf.readthedocs.io/en/stable/kwargs/#body-parts
Thanks nolar