alekc / terraform-provider-kubectl

Mozilla Public License 2.0
160 stars 9 forks source link

Support `--cascade` option on deletion. #145

Open fullykubed opened 3 months ago

fullykubed commented 3 months ago

When Kubernetes removes certain controllers like StatefulSets, you have the ability to control whether it also deletes the underlying resources such as the Pods / PVCs (reference).

It would be nice to be able to configure this setting to be able to retain some resources after deleting the main controllers.

alekc commented 3 months ago

Tbh I am against this. The whole purpose of IAC is to manage explicit resources declared in the code, so anything outside it, should be managed through an explicit IAC declaration. I do not see any good example when this --cascade would be useful, do you have any use case?

fullykubed commented 3 months ago

I agree. However, the purpose of this is actually to aid in making updates to controllers.

Many Kubernetes controllers such as StatefulSets have immutable fields. For example, in StatefulSets, .spec.volumeClaimTemplates is immutable.

As a result, the only way to update this field is to delete the StatefulSet and create a new one. The only way to do that without deleting all of the Pods and PVCs is via --cascade=orphan.

This impacts many controllers, both ones built-in to Kubernetes and third-party controllers as well.

Having the ability to specify --cascade would easy a burden that currently requires intervention outside of IAC.

Now in a perfect world, we would also be able to apply this only on "recreate" and not on full "delete," but my understanding is that is not very straightforward?

stevehipwell commented 1 month ago

@fullykubed now that #165 has been merged you should be able to easily add the orphan cascade option to the delete_cascade input.

fullykubed commented 1 month ago

@stevehipwell Thanks for the heads up.

@alekc Would it be fine to add orphan to the list of available options for delete_cascade?