Skip to content

docker: DockerCluster never been deleted if not correctly owned by Cluster #12796

@dmvolod

Description

@dmvolod

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.

// 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

Metadata

Metadata

Assignees

Labels

area/provider/infrastructure-dockerIssues or PRs related to the docker infrastructure providerhelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.priority/backlogHigher priority than priority/awaiting-more-evidence.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions