kubernetes-sigs/cluster-api-provider-gcp

Allow clusters to be deleted without deleting custom `subnets`.

jwmay2012 opened this issue · 1 comments

/kind feature

Describe the solution you'd like
Allow custom subnets (those created outside of CAPG) to be retained upon cluster deletion.

Anything else you would like to add:

We create our Networks/SubNetworks outside CAPI and keep non-cluster machines in them. When we want to delete a cluster, the cluster.cluster.x-k8s.io finalizer never gets removed because CAPG forever tries and fails to delete the Network and SubNetwork because they contain other machines.

I would like to submit a PR to skip Network/SubNetwork deletion step in the func (r *GCPClusterReconciler) reconcileDelete(...) function.

Proposed Configuration Solutions

  1. Add a new option to the GCPCluster.Spec.Network spec. reclaimPolicy: Retain which would default to Delete. Based off PersistentVolumes retention policy convention. But any other name that works for this project would be fine.

  2. Use the Network Description to identify non-CAPG created networks, and refrain from deleting them. Networks and Subnetworks don't have GCP labels and seem to only have a Description for metadata. The Network description is set via infrav1.ClusterTagKey(s.Name()) which resolves to "cpag-cluster-" + Cluster.Metadata.Name. We could make this more obviously "machine created" by changing it to Created By CAPG: capg-cluster-mycluster:240f34f19636c80eeeb41ccf4dbd390b where the hash is md5|sha1|sha256|w/e of capg-cluster-mycluster. Then during cluster reconcileDelete, we check if the Network description matches our "machine created" string. If yes, then continue with default behavior auto-delete. If not, then we assume its not created by CAPG and skip deleting Network/SubNetwork.

Any other suggested/preferred configuration options would appreciated.

I'm finding out more specifics about the issue.
Networks DO skip deletion if their description is not equal to infrav1.ClusterTagKey(s.Name()). Just noticed this.
Our issue is with SubNetworks not skipping in the same way.

I'll create a PR that adds this similar logic to subnets.