Skip to content
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
46 changes: 20 additions & 26 deletions pkg/kubenest/controller/virtualcluster_init_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *VirtualClusterInitController) Reconcile(ctx context.Context, request re
klog.V(2).InfoS("Virtual Cluster has been deleted", "Virtual Cluster", request)
return reconcile.Result{}, nil
}
return reconcile.Result{RequeueAfter: RequeueTime}, nil
return reconcile.Result{}, nil
}
updatedCluster := originalCluster.DeepCopy()
updatedCluster.Status.Reason = ""
Expand All @@ -132,44 +132,35 @@ func (c *VirtualClusterInitController) Reconcile(ctx context.Context, request re
err := c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}

if err = c.nodeManager.NodeUpdate(ctx, *updatedCluster); err != nil {
if len(updatedCluster.Spec.Kubeconfig) == 0 {
klog.Warningf("virtualcluster.spec.kubeconfig is nil, but status is deleting. %s %s.", updatedCluster.Name, updatedCluster.Status.Phase)
} else if err = c.nodeManager.NodeUpdate(ctx, *updatedCluster); err != nil {
updatedCluster.Status.Phase = v1alpha1.Pending
updatedCluster.Status.Reason = err.Error()
err := c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error delete virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error delete virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error delete virtualcluster %s status", updatedCluster.Name)
}
return reconcile.Result{}, err
return reconcile.Result{RequeueAfter: RequeueTime}, err
}

// if err = c.nodeManager.NodeDelete(ctx, *updatedCluster); err != nil {
// updatedCluster.Status.Phase = v1alpha1.Pending
// updatedCluster.Status.Reason = err.Error()
// err := c.Update(updatedCluster)
// if err != nil {
// klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
// return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
// }
// return reconcile.Result{}, err
// }

klog.V(2).Infof(" all node is deleted, vc: %s", updatedCluster.Name)

updatedCluster.Status.Phase = v1alpha1.AllNodeDeleted
err = c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}

err = c.destroyVirtualCluster(updatedCluster)
if err != nil {
klog.Errorf("Destroy virtual cluter %s failed. err: %s", updatedCluster.Name, err.Error())
return reconcile.Result{}, errors.Wrapf(err, "Destroy virtual cluter %s failed. err: %s", updatedCluster.Name, err.Error())
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Destroy virtual cluter %s failed. err: %s", updatedCluster.Name, err.Error())
}
return c.removeFinalizer(updatedCluster)
}
Expand All @@ -192,25 +183,25 @@ func (c *VirtualClusterInitController) Reconcile(ctx context.Context, request re
err := c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s. err: %s", updatedCluster.Name, err.Error())
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}
return reconcile.Result{}, errors.Wrap(err, "Error createVirtualCluster")
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrap(err, "Error createVirtualCluster")
}
updatedCluster.Status.Phase = v1alpha1.Initialized
err = c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s. %v", updatedCluster.Name, updatedCluster.Status.Phase, err)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}
if err = c.nodeManager.NodeUpdate(ctx, *updatedCluster); err != nil {
updatedCluster.Status.Phase = v1alpha1.Pending
updatedCluster.Status.Reason = err.Error()
err := c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}
return reconcile.Result{}, err
return reconcile.Result{RequeueAfter: RequeueTime}, err
}
name, namespace := request.Name, request.Namespace
return reconcile.Result{}, c.DoAllNodeReadyCheck(name, namespace, originalCluster, updatedCluster)
Expand All @@ -229,23 +220,26 @@ func (c *VirtualClusterInitController) Reconcile(ctx context.Context, request re
}
err = c.assignWorkNodes(updatedCluster)
if err != nil {
updatedCluster.Status.Phase = v1alpha1.Pending
updatedCluster.Status.Reason = err.Error()
err := c.Update(updatedCluster)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s", updatedCluster.Name)
}
updatedCluster.Status.Phase = v1alpha1.Updating
err = c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}
if err = c.nodeManager.NodeUpdate(ctx, *updatedCluster); err != nil {
updatedCluster.Status.Phase = v1alpha1.Pending
updatedCluster.Status.Reason = err.Error()
err := c.Update(updatedCluster)
if err != nil {
klog.Errorf("Error update virtualcluster %s status to %s", updatedCluster.Name, updatedCluster.Status.Phase)
return reconcile.Result{}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, errors.Wrapf(err, "Error update virtualcluster %s status", updatedCluster.Name)
}
return reconcile.Result{}, err
return reconcile.Result{RequeueAfter: RequeueTime}, err
}
name, namespace := request.Name, request.Namespace
return reconcile.Result{}, c.DoAllNodeReadyCheck(name, namespace, originalCluster, updatedCluster)
Expand Down
Loading