Skip to content

Commit 43d2eee

Browse files
committed
Only delete network if it has our label
1 parent 693a0bc commit 43d2eee

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

controllers/hetznercluster_controller.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,15 @@ func (r *HetznerClusterReconciler) reconcileDelete(ctx context.Context, clusterS
344344
return reconcile.Result{}, fmt.Errorf("failed to delete load balancers for HetznerCluster %s/%s: %w", hetznerCluster.Namespace, hetznerCluster.Name, err)
345345
}
346346

347-
// delete the network
348-
if err := network.NewService(clusterScope).Delete(ctx); err != nil {
349-
return reconcile.Result{}, fmt.Errorf("failed to delete network for HetznerCluster %s/%s: %w", hetznerCluster.Namespace, hetznerCluster.Name, err)
347+
// delete the network only if it is owned by us
348+
if hetznerCluster.Status.Network != nil {
349+
if hetznerCluster.Status.Network.Labels[hetznerCluster.ClusterTagKey()] == string(infrav1.ResourceLifecycleOwned) {
350+
if err := network.NewService(clusterScope).Delete(ctx); err != nil {
351+
return reconcile.Result{}, fmt.Errorf("failed to delete network for HetznerCluster %s/%s: %w", hetznerCluster.Namespace, hetznerCluster.Name, err)
352+
}
353+
} else {
354+
clusterScope.V(1).Info("network is not owned by us", "id", hetznerCluster.Status.Network.ID, "labels", hetznerCluster.Status.Network.Labels)
355+
}
350356
}
351357

352358
// delete the placement groups

0 commit comments

Comments
 (0)