Skip to content

Commit 0baf8c1

Browse files
committed
Only delete network if it has our label
1 parent 5f927d2 commit 0baf8c1

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
@@ -346,9 +346,15 @@ func (r *HetznerClusterReconciler) reconcileDelete(ctx context.Context, clusterS
346346
return reconcile.Result{}, fmt.Errorf("failed to delete load balancers for HetznerCluster %s/%s: %w", hetznerCluster.Namespace, hetznerCluster.Name, err)
347347
}
348348

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

354360
// delete the placement groups

0 commit comments

Comments
 (0)