kubernetes-sigs/cluster-api

clusterctl delete should be idempotent

Open

#7,411 opened on Oct 15, 2022

View on GitHub
 (12 comments) (1 reaction) (0 assignees)Go (1,532 forks)auto 404
area/clusterctlhelp wantedkind/buglifecycle/stalepriority/important-longtermtriage/accepted

Repository metrics

Stars
 (4,267 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide