Skip to content

🐛 Wait for CAPD Cluster dependecies deletion#13329

Open
alexander-demicev wants to merge 1 commit intokubernetes-sigs:mainfrom
alexander-demicev:capddeletion
Open

🐛 Wait for CAPD Cluster dependecies deletion#13329
alexander-demicev wants to merge 1 commit intokubernetes-sigs:mainfrom
alexander-demicev:capddeletion

Conversation

@alexander-demicev
Copy link
Contributor

What this PR does / why we need it:

We've noticed an issue in the CAPRKE2 tests with the deletion of a CAPD cluster. When not done in the correct order, the CAPD cluster can be deleted before the machines, this is blocking machine deletion. This PR introduces similar logic that already exists in CAPA to wait for dependent objects to be deleted before removing the infrastructure cluster.
CAPA PR for reference: kubernetes-sigs/cluster-api-provider-aws#5365

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

/area provider/infrastructure-docker

Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
@k8s-ci-robot k8s-ci-robot added the area/provider/infrastructure-docker Issues or PRs related to the docker infrastructure provider label Feb 11, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign justinsb for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 11, 2026
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 11, 2026
Copy link
Contributor

@salasberryfin salasberryfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alexander-demicev.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2026
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

DetailsGit tree hash: fc4f364df87758c2da1ef0ef44b59a251b0bc364

@@ -117,10 +117,27 @@ func (r *ClusterBackEndReconciler) ReconcileNormal(ctx context.Context, cluster

// ReconcileDelete handle docker backend for delete DevMachines.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've noticed an issue in the CAPRKE2 tests with the deletion of a CAPD cluster. When not done in the correct order, the CAPD cluster can be deleted before the machines, this is blocking machine deletion.

This should be impossible. I wonder if there is an issue elsewhere.

Please see:

if cluster.Spec.InfrastructureRef.IsDefined() {
(and all the checks above before we delete the InfraCluster)

/hold

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbueringer Thanks for the review. I wonder if the problem we're seeing now is the same one we saw in CAPA a while ago.
Let's say I run kubectl delete -f cluster.yaml, where the yaml contains all manifests for the cluster. The Cluster gets a deletion timestamp, and the timestamp is propagated to the DockerCluster through owner references. The Cluster controller includes the dependency check, but the DockerCluster starts reconciling anyway. ReconcileDelete removes the finalizer before the DockerMachines are gone and before the Cluster controller's checks pass. This causes the DockerCluster to be deleted while the DockerMachines remain stuck.

Copy link
Member

@sbueringer sbueringer Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be.

To clarify. The manifest contains the DockerCluster?

Deleting all objects of an Cluster at the same time is entirely unsupported to be honest (similar to how just deleting the entire namespace which also leads to deletionTimestamps on all objects at the same time is unsupported).

Cluster gets a deletion timestamp, and the timestamp is propagated to the DockerCluster through owner references

I think in your case the deletionTimestamp comes directly from kubectl delete. ownerRefs should only propagate the deletionTimestamp after the Cluster object is gone from etcd.

Copy link
Member

@sbueringer sbueringer Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why deleting everything at the same time is unsupported is because it's a huge effort to support this correctly.

Every single controller would need safe-guards to check other resources to figure out if it is actually allowed to already go through reconcileDelete.

E.g. the DockerMachine controller would have figure out if it's already time to delete worker Machines (vs. CP Machines that should be deleted later), etc...

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 11, 2026
@kkaempf kkaempf moved this to PR to be reviewed in CAPI / Turtles Feb 11, 2026
@kkaempf kkaempf moved this from PR to be reviewed to Blocked in CAPI / Turtles Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/provider/infrastructure-docker Issues or PRs related to the docker infrastructure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants