Closed devdattakulkarni closed 1 year ago
@eminalparslan Here is a high-level overview of how this can be achieved.
In mutating webhook, when we receive delete for ResourceComposition instance, retrieve the kind, group, version, etc. details of the child CRD defined by that ResourceComposition (check lines 1274 - 1285 of https://github.com/cloud-ark/kubeplus/blob/master/mutating-webhook/webhook.go). Then, using dynamicClient query all the application instances belonging to that group, version, kind (GVR). Refer to https://github.com/cloud-ark/kubeplus/blob/master/platform-operator/helm-pod/main.go#L423. For each application instance, check the status to see if helmrelease is populated or not. Reject the delete call if the helmrelease value for any instance is empty.
Application instances are created by creating an instance of child CRD defined in a ResourceComposition instance. It is possible that K8s resources comprising an application instance take a while to spin up. During this time we should prevent the deletion of the ResourceComposition instance. If ResourceComposition delete is allowed to proceed, it will cause the application instance to get deleted. Eventually, when the k8s resources start up, they will be orphaned as there won't be a parent application instance to manage them.