Arkady Sharkansky
Arkady Sharkansky

Reputation: 123

cascading delete using kopf.adopt()

Started using kopf pretty recently. its great!! also kind of new k8s in general...

I have a pretty simple scenario. Two crds, parent and child... parent is created first. the child is created sometime later, but not by the parent... is there a way for child object to get its self 'adopted/owned' by the parent instance using kopf.adopt() method.

it would greatly simplify or even eliminate my cascading delete code.

or is there way using k8s client to add an ownerReference to an existing custom objects metadata?

Thanks in advance...

Upvotes: 0

Views: 102

Answers (1)

Arkady Sharkansky
Arkady Sharkansky

Reputation: 123

after a little bit of hacking i came up with bit of code:

merge_patch = {
    "metadata": {
        "ownerReferences": [
            {
                "apiVersion": "siccat.com/v1",
                "blockOwnerDeletion": True,
                "kind": "Parent",
                "name": parent_box.metadata.name,
                "uid": parent_box.metadata.uid
            }
        ]}
}
api.patch_namespaced_custom_object(namespace=namespace, name=name,
                                   group="siccat.com",
                                   version="v1",
                                   plural="children",
                                   body=merge_patch)

essentially performing a patch in the create event handler...

this enables a cascading delete...

wondering if there is a better way accomplish the same thing?

Upvotes: 0

Related Questions