Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check nutanixmachine resources when deleting nutanixcluster #304

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions controllers/nutanixcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -28,7 +29,6 @@ import (
kerrors "k8s.io/apimachinery/pkg/util/errors"
coreinformers "k8s.io/client-go/informers/core/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
capiutil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
Expand Down Expand Up @@ -204,8 +204,21 @@ func (r *NutanixClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
func (r *NutanixClusterReconciler) reconcileDelete(rctx *nctx.ClusterContext) (reconcile.Result, error) {
log := ctrl.LoggerFrom(rctx.Context)
log.Info("Handling NutanixCluster deletion")
// Check if there are nutanixmachine resources left. Only continue if all of them have been cleaned
nutanixMachines, err := rctx.GetNutanixMachinesInCluster(r.Client)
if err != nil {
log.Error(err, "error occurred while checking nutanixmachines during cluster deletion")
return reconcile.Result{}, err
}

if len(nutanixMachines) > 0 {
log.Info(fmt.Sprintf("waiting for %d nutanixmachines to be deleted", len(nutanixMachines)))
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}

log.V(1).Info("no existing nutanixMachine resources found. Continuing with deleting cluster")

err := r.reconcileCategoriesDelete(rctx)
err = r.reconcileCategoriesDelete(rctx)
if err != nil {
log.Error(err, "error occurred while running deletion of categories")
return reconcile.Result{}, err
Expand Down Expand Up @@ -250,8 +263,8 @@ func (r *NutanixClusterReconciler) reconcileNormal(rctx *nctx.ClusterContext) (r

err := r.reconcileCategories(rctx)
tuxtof marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
errorMsg := fmt.Errorf("failed to reconcile categories for cluster %s: %v", rctx.Cluster.Name, err)
rctx.SetFailureStatus(capierrors.CreateClusterError, errorMsg)
log.Error(err, "error occurred while reconciling categories")
tuxtof marked this conversation as resolved.
Show resolved Hide resolved
// Don't return fatal error but keep retrying until categories are created.
yannickstruyf3 marked this conversation as resolved.
Show resolved Hide resolved
return reconcile.Result{}, err
}

Expand Down
Loading