optimize karmadactl unjoin command (#254)
Signed-off-by: lihanbo <lihanbo2@huawei.com>
This commit is contained in:
parent
3b3fde5ccd
commit
dcad956744
|
@ -122,8 +122,9 @@ func (c *Controller) ensureRemoveExecutionSpace(cluster *v1alpha1.Cluster) (bool
|
|||
}
|
||||
|
||||
executionSpaceObj := &corev1.Namespace{}
|
||||
err = c.Client.Get(context.TODO(), types.NamespacedName{Namespace: executionSpaceName}, executionSpaceObj)
|
||||
err = c.Client.Get(context.TODO(), types.NamespacedName{Name: executionSpaceName}, executionSpaceObj)
|
||||
if apierrors.IsNotFound(err) {
|
||||
klog.V(2).Infof("Removed execution space(%s)", executionSpaceName)
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -117,18 +117,11 @@ func RunUnjoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, opts CommandUnjoin
|
|||
}
|
||||
|
||||
controlPlaneKarmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
controlPlaneKubeClient := kubeclient.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
|
||||
// todo: taint cluster object instead of deleting execution space.
|
||||
// Once the cluster is tainted, eviction controller will delete all Work in the execution space of the cluster.
|
||||
executionSpaceName, err := names.GenerateExecutionSpaceName(opts.ClusterName)
|
||||
// delete the cluster object in host cluster that associates the unjoining cluster
|
||||
err = deleteClusterObject(controlPlaneKarmadaClient, opts.ClusterName, opts.DryRun)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = deleteExecutionSpace(controlPlaneKubeClient, executionSpaceName, opts.DryRun)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete execution space %s, error: %v", executionSpaceName, err)
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", opts.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -167,13 +160,6 @@ func RunUnjoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, opts CommandUnjoin
|
|||
}
|
||||
}
|
||||
|
||||
// delete the cluster object in host cluster that associates the unjoining cluster
|
||||
err = deleteClusterObject(controlPlaneKarmadaClient, opts.ClusterName, opts.DryRun)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", opts.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -241,37 +227,6 @@ func deleteNamespaceFromUnjoinCluster(clusterKubeClient kubeclient.Interface, na
|
|||
return nil
|
||||
}
|
||||
|
||||
func deleteExecutionSpace(hostClient kubeclient.Interface, namespace string, dryRun bool) error {
|
||||
if dryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := util.DeleteNamespace(hostClient, namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// make sure the execution space has been deleted
|
||||
err = wait.Poll(1*time.Second, 30*time.Second, func() (done bool, err error) {
|
||||
exist, err := util.IsNamespaceExist(hostClient, namespace)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get execution space %s. err: %v", namespace, err)
|
||||
return false, err
|
||||
}
|
||||
if !exist {
|
||||
return true, nil
|
||||
}
|
||||
klog.Infof("Waiting for the execution space %s to be deleted", namespace)
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete execution space %s, error: %v", namespace, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteClusterObject delete the cluster object in host cluster that associates the unjoining cluster
|
||||
func deleteClusterObject(controlPlaneKarmadaClient *karmadaclientset.Clientset, clusterName string, dryRun bool) error {
|
||||
if dryRun {
|
||||
|
|
Loading…
Reference in New Issue