-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
What steps did you take and what happened?
If you create a DockerCluster but don't create a Cluster object or specify an incorrect name in infrastructureRef, and then try to delete it, you won't be able to do so, since the presence of a reference to the Cluster object is always checked before the finalization step.
cluster-api/test/infrastructure/docker/internal/controllers/dockercluster_controller.go
Lines 73 to 86 in 7bd466a
// Add finalizer first if not set to avoid the race condition between init and delete. | |
if finalizerAdded, err := finalizers.EnsureFinalizer(ctx, r.Client, dockerCluster, infrav1.ClusterFinalizer); err != nil || finalizerAdded { | |
return ctrl.Result{}, err | |
} | |
// Fetch the Cluster. | |
cluster, err := util.GetOwnerCluster(ctx, r.Client, dockerCluster.ObjectMeta) | |
if err != nil { | |
return ctrl.Result{}, err | |
} | |
if cluster == nil { | |
log.Info("Waiting for Cluster Controller to set OwnerRef on DockerCluster") | |
return ctrl.Result{}, nil | |
} |
In this case, we should move validation if cluster == nil
later, after finalizer delete step, to avoid confusion.
The same logic is used, for example, in the vsphere and other infrastructure controllers.
What did you expect to happen?
You can delete DockerCluster under any conditions and settings
Cluster API version
v1.9.11
Kubernetes version
v1.29.3
Anything else you would like to add?
Can be reproduced in latest main.
I will take care about this fix when accepted.
Label(s) to be applied
/kind bug
One or more /area label. See https://github.com/kubernetes-sigs/cluster-api/labels?q=area for the list of labels.
/area provider/infrastructure-docker