Skip to content

clusterctl delete should be idempotent #7411

@jessehu

Description

@jessehu

What steps did you take and what happened:

$ clusterctl delete --all --include-crd --include-namespace -v 4
Deleting Provider="bootstrap-kubeadm" Version="v1.2.3" Namespace="capi-kubeadm-bootstrap-system"
Deleting Provider="control-plane-kubeadm" Version="v1.2.3" Namespace="capi-kubeadm-control-plane-system"
Deleting Provider="cluster-api" Version="v1.2.3" Namespace="capi-system"
Deleting Provider="infrastructure-ipam" Version="v1.2.0" Namespace="capm3-system"  ## This is a provider installed by us
Error: failed to list objects for the "cluster.x-k8s.io/v1beta1, Kind=Machine" GroupVersionKind: action failed after 9 attempts: the server could not find the requested resource (get machines.cluster.x-k8s.io)

$ clusterctl delete --all --include-crd --include-namespace -v 4
Error: failed to check Cluster API version: customresourcedefinitions.apiextensions.k8s.io "clusters.cluster.x-k8s.io" not found

$ k get crd |grep x-k8s
providers.clusterctl.cluster.x-k8s.io     2022-10-14T10:40:16Z

What did you expect to happen:
After the 1st run of clusterctl failed, we're able to run the clusterctl again and it deletes all remaining providers.

Anything else you would like to add:
The 2nd run of clusterctl failed because clusterctl requires the "clusters.cluster.x-k8s.io" CRD must exist (see source code) but this CRD was already deleted in the 1st run of clusterctl.

If I manually create the "clusters.cluster.x-k8s.io" CRD (similiar to clusterClient.ProviderInventory().EnsureCustomResourceDefinitions() at L74 in delete.go), the 2nd run of clusterctl is able to delete all remaining providers. If the 2nd run failed too due to failed to list objects for the ..., we can run clusterctl multi times until it succeeds.

So my question is:

  • is calling CheckCAPIContract() necessary at the beginning of clusterctl delete? CheckCAPIContract() ensures CAPI is installed by checking "clusters.cluster.x-k8s.io" CRD existence.
  • or can we add the option CheckCAPIContractOption.AllowCAPINotInstalled in DeleteOptions and pass it to CheckCAPIContract(options ...CheckCAPIContractOption)?

Environment:

  • clusterctl version: &version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.3", GitCommit:"bb377163f141d69b7a61479756ee96891f6670bd", GitTreeState:"clean", BuildDate:"2022-10-10T12:30:14Z", GoVersion:"go1.18.7", Compiler:"gc", Platform:"darwin/arm64"}
  • kind version: kind v0.12.0 go1.17.8 darwin/arm64,
  • Kubernetes version: (use kubectl version): v1.23.4
  • OS (e.g. from /etc/os-release):

/kind bug
/area clusterctl

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/clusterctlIssues or PRs related to clusterctlhelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.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