diff --git a/pkg/controllers/provisioningv2/cluster/controller.go b/pkg/controllers/provisioningv2/cluster/controller.go index 988cee3a882..d2560af4865 100644 --- a/pkg/controllers/provisioningv2/cluster/controller.go +++ b/pkg/controllers/provisioningv2/cluster/controller.go @@ -342,7 +342,7 @@ func (h *handler) updateStatus(objs []runtime.Object, cluster *v1.Cluster, statu ready = true } for _, messageCond := range existing.Status.Conditions { - if messageCond.Type == "Updated" || messageCond.Type == "Provisioned" || messageCond.Type == "Removed" { + if messageCond.Type == "Updated" || messageCond.Type == "Provisioned" || messageCond.Type == "Removed" || messageCond.Type == "Deleting" { continue } diff --git a/pkg/controllers/provisioningv2/cluster/remove.go b/pkg/controllers/provisioningv2/cluster/remove.go index 032cf2da01f..34ce76fdbc8 100644 --- a/pkg/controllers/provisioningv2/cluster/remove.go +++ b/pkg/controllers/provisioningv2/cluster/remove.go @@ -2,6 +2,7 @@ package cluster import ( "fmt" + "github.com/rancher/wrangler/pkg/genericcondition" "time" v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" @@ -14,6 +15,10 @@ import ( ) func (h *handler) OnMgmtClusterRemove(_ string, cluster *v3.Cluster) (*v3.Cluster, error) { + rke2.Deleting.SetStatus(cluster, "True") + rke2.Deleting.SetStatusBool(cluster, true) + rke2.Deleting.Reason(cluster, "") + rke2.Deleting.Message(cluster, "") provisioningClusters, err := h.clusterCache.GetByIndex(ByCluster, cluster.Name) if err != nil { return nil, err @@ -42,7 +47,16 @@ func (h *handler) OnMgmtClusterRemove(_ string, cluster *v3.Cluster) (*v3.Cluste func (h *handler) OnClusterRemove(_ string, cluster *v1.Cluster) (*v1.Cluster, error) { oldStatus := cluster.Status cluster = cluster.DeepCopy() - + // set status as "Deleting" + rke2.Deleting.SetStatus(cluster, "True") + rke2.Deleting.SetStatusBool(cluster, true) + rke2.Deleting.Reason(cluster, "") + rke2.Deleting.Message(cluster, "") + newCond := genericcondition.GenericCondition{ + Type: "Deleting", + Status: "True", + } + cluster.Status.Conditions = append(cluster.Status.Conditions, newCond) err := rke2.DoRemoveAndUpdateStatus(cluster, h.doClusterRemove(cluster), h.clusters.EnqueueAfter) if equality.Semantic.DeepEqual(oldStatus, cluster.Status) { diff --git a/pkg/controllers/provisioningv2/rke2/common.go b/pkg/controllers/provisioningv2/rke2/common.go index f1f2a8ede50..eef1211edde 100644 --- a/pkg/controllers/provisioningv2/rke2/common.go +++ b/pkg/controllers/provisioningv2/rke2/common.go @@ -91,6 +91,7 @@ const ( Waiting = condition.Cond("Waiting") Pending = condition.Cond("Pending") Removed = condition.Cond("Removed") + Deleting = condition.Cond("Deleting") PlanApplied = condition.Cond("PlanApplied") InfrastructureReady = condition.Cond(capi.InfrastructureReadyCondition) SystemUpgradeControllerReady = condition.Cond("SystemUpgradeControllerReady") @@ -264,9 +265,9 @@ func PlanSecretFromBootstrapName(bootstrapName string) string { func DoRemoveAndUpdateStatus(obj metav1.Object, doRemove func() (string, error), enqueueAfter func(string, string, time.Duration)) error { if !Provisioned.IsTrue(obj) || !Waiting.IsTrue(obj) || !Pending.IsTrue(obj) { // Ensure the Removed obj appears in the UI. - Provisioned.SetStatus(obj, "True") Waiting.SetStatus(obj, "True") Pending.SetStatus(obj, "True") + Provisioned.SetStatus(obj, "True") } message, err := doRemove() if errors.Is(err, generic.ErrSkip) {