From 548babf4346298c1e461ac87b84f3df0abbf22c0 Mon Sep 17 00:00:00 2001 From: ONE7live Date: Fri, 13 Oct 2023 11:05:04 +0800 Subject: [PATCH] fix: Optimize kosmos install waiting process Signed-off-by: ONE7live --- pkg/kosmosctl/install/install.go | 6 ++- pkg/kosmosctl/join/join.go | 76 ++++++++++++++++------------ pkg/kosmosctl/uninstall/uninstall.go | 8 +-- pkg/kosmosctl/unjoin/unjoin.go | 55 +++++++++++--------- pkg/utils/constants.go | 5 +- 5 files changed, 87 insertions(+), 63 deletions(-) diff --git a/pkg/kosmosctl/install/install.go b/pkg/kosmosctl/install/install.go index 3e5fdefbe..a10bd87ff 100644 --- a/pkg/kosmosctl/install/install.go +++ b/pkg/kosmosctl/install/install.go @@ -255,7 +255,8 @@ func (o *CommandInstallOptions) runClusterlink() error { return fmt.Errorf("kosmosctl install clusterlink run error, deployment options failed: %v", err) } } - if err = util.WaitDeploymentReady(o.Client, clusterlinkDeployment, o.WaitTime); err != nil { + label := map[string]string{"app": clusterlinkDeployment.Labels["app"]} + if err = util.WaitPodReady(o.Client, clusterlinkDeployment.Namespace, util.MapToString(label), o.WaitTime); err != nil { return fmt.Errorf("kosmosctl install clusterlink run error, deployment options failed: %v", err) } else { klog.Info("Deployment clusterlink-network-manager has been created.") @@ -365,7 +366,8 @@ func (o *CommandInstallOptions) runClustertree() error { return fmt.Errorf("kosmosctl install clustertree run error, deployment options failed: %v", err) } } - if err = util.WaitDeploymentReady(o.Client, clustertreeDeployment, o.WaitTime); err != nil { + label := map[string]string{"app": clustertreeDeployment.Labels["app"]} + if err = util.WaitPodReady(o.Client, clustertreeDeployment.Namespace, util.MapToString(label), o.WaitTime); err != nil { return fmt.Errorf("kosmosctl install clustertree run error, deployment options failed: %v", err) } else { klog.Info("Deployment clustertree-knode-manager has been created.") diff --git a/pkg/kosmosctl/join/join.go b/pkg/kosmosctl/join/join.go index 0f707e10f..02273ed27 100644 --- a/pkg/kosmosctl/join/join.go +++ b/pkg/kosmosctl/join/join.go @@ -31,16 +31,16 @@ import ( var joinExample = templates.Examples(i18n.T(` # Join cluster resource from a directory containing cluster.yaml, e.g: - kosmosctl join cluster --cluster-name=[cluster-name] --master-kubeconfig=[master-kubeconfig] --cluster-kubeconfig=[cluster-kubeconfig] + kosmosctl join cluster --name=[cluster-name] --master-kubeconfig=[master-kubeconfig] --cluster-kubeconfig=[cluster-kubeconfig] # Join cluster resource without master-kubeconfig, e.g: - kosmosctl join cluster --cluster-name=[cluster-name] --cluster-kubeconfig=[cluster-kubeconfig] + kosmosctl join cluster --name=[cluster-name] --cluster-kubeconfig=[cluster-kubeconfig] # Join knode resource, e.g: - kosmosctl join knode --knode-name=[knode-name] --master-kubeconfig=[master-kubeconfig] --cluster-kubeconfig=[cluster-kubeconfig] + kosmosctl join knode --name=[knode-name] --master-kubeconfig=[master-kubeconfig] --cluster-kubeconfig=[cluster-kubeconfig] # Join knode resource without master-kubeconfig, e.g: - kosmosctl join knode --knode-name=[knode-name] --cluster-kubeconfig=[cluster-kubeconfig] + kosmosctl join knode --name=[knode-name] --cluster-kubeconfig=[cluster-kubeconfig] `)) type CommandJoinOptions struct { @@ -48,7 +48,7 @@ type CommandJoinOptions struct { MasterKubeConfigStream []byte ClusterKubeConfig string - ClusterName string + Name string CNI string DefaultNICName string ImageRegistry string @@ -56,8 +56,6 @@ type CommandJoinOptions struct { UseProxy string WaitTime int - KnodeName string - Client kubernetes.Interface DynamicClient *dynamic.DynamicClient } @@ -84,12 +82,11 @@ func NewCmdJoin(f ctlutil.Factory) *cobra.Command { flags := cmd.Flags() flags.StringVar(&o.MasterKubeConfig, "master-kubeconfig", "", "Absolute path to the master kubeconfig file.") flags.StringVar(&o.ClusterKubeConfig, "cluster-kubeconfig", "", "Absolute path to the cluster kubeconfig file.") - flags.StringVar(&o.ClusterName, "cluster-name", "", "Specify the name of the member cluster to join.") + flags.StringVar(&o.Name, "name", "", "Specify the name of the resource to join.") flags.StringVar(&o.CNI, "cni", "", "The cluster is configured using cni and currently supports calico and flannel.") flags.StringVar(&o.DefaultNICName, "default-nic", "", "Set default network interface card.") flags.StringVar(&o.ImageRegistry, "private-image-registry", utils.DefaultImageRepository, "Private image registry where pull images from. If set, all required images will be downloaded from it, it would be useful in offline installation scenarios. In addition, you still can use --kube-image-registry to specify the registry for Kubernetes's images.") - flags.StringVar(&o.NetworkType, "network-type", "gateway", "Set the cluster network connection mode, which supports gateway and p2p modes. Gateway is used by default.") - flags.StringVar(&o.KnodeName, "knode-name", "", "Specify the name of the knode to join.") + flags.StringVar(&o.NetworkType, "network-type", utils.NetworkTypeP2P, "Set the cluster network connection mode, which supports gateway and p2p modes, p2p is used by default.") flags.StringVar(&o.UseProxy, "use-proxy", "false", "Set whether to enable proxy.") flags.IntVarP(&o.WaitTime, "wait-time", "", 120, "Wait the specified time for the Kosmos install ready.") @@ -142,16 +139,20 @@ func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error { } func (o *CommandJoinOptions) Validate(args []string) error { + if len(o.Name) == 0 { + return fmt.Errorf("kosmosctl join validate error, resource name is not valid") + } + switch args[0] { case "cluster": - _, err := o.DynamicClient.Resource(util.ClusterGVR).Get(context.TODO(), o.ClusterName, metav1.GetOptions{}) + _, err := o.DynamicClient.Resource(util.ClusterGVR).Get(context.TODO(), o.Name, metav1.GetOptions{}) if err != nil { if apierrors.IsAlreadyExists(err) { return fmt.Errorf("kosmosctl join validate error, clsuter already exists: %s", err) } } case "knode": - _, err := o.DynamicClient.Resource(util.KnodeGVR).Get(context.TODO(), o.KnodeName, metav1.GetOptions{}) + _, err := o.DynamicClient.Resource(util.KnodeGVR).Get(context.TODO(), o.Name, metav1.GetOptions{}) if err != nil && apierrors.IsAlreadyExists(err) { if apierrors.IsAlreadyExists(err) { return fmt.Errorf("kosmosctl join validate error, knode already exists: %s", err) @@ -183,7 +184,7 @@ func (o *CommandJoinOptions) runCluster() error { klog.Info("Start registering cluster to kosmos control plane...") // 1. create cluster in master clusterByte, err := util.GenerateCustomResource(manifest.ClusterCR, manifest.ClusterReplace{ - ClusterName: o.ClusterName, + ClusterName: o.Name, CNI: o.CNI, DefaultNICName: o.DefaultNICName, ImageRepository: o.ImageRegistry, @@ -200,15 +201,16 @@ func (o *CommandJoinOptions) runCluster() error { } _, err = o.DynamicClient.Resource(util.ClusterGVR).Namespace("").Create(context.TODO(), obj, metav1.CreateOptions{}) if err != nil { - return fmt.Errorf("(cluster) kosmosctl join run error, create cluster failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create cluster failed: %s", err) } + klog.Info("Cluster: " + o.Name + " has been created.") // 2. create namespace in member namespace := &corev1.Namespace{} namespace.Name = utils.DefaultNamespace _, err = o.Client.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster namespace) kosmosctl join run error, create namespace failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create namespace failed: %s", err) } // 3. create secret in member @@ -224,59 +226,66 @@ func (o *CommandJoinOptions) runCluster() error { } _, err = o.Client.CoreV1().Secrets(secret.Namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster secret) kosmosctl join run error, create secret failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create secret failed: %s", err) } + klog.Info("Secret: " + secret.Name + " has been created.") // 4. create rbac in member clusterRole, err := util.GenerateClusterRole(manifest.ClusterlinkClusterRole, nil) if err != nil { - return fmt.Errorf("(cluster rbac) kosmosctl join run error, generate clusterrole failed: %s", err) + return fmt.Errorf("kosmosctl join run error, generate clusterrole failed: %s", err) } _, err = o.Client.RbacV1().ClusterRoles().Create(context.TODO(), clusterRole, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster rbac) kosmosctl join run error, create clusterrole failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create clusterrole failed: %s", err) } + klog.Info("ClusterRole: " + clusterRole.Name + " has been created.") + clusterRoleBinding, err := util.GenerateClusterRoleBinding(manifest.ClusterlinkClusterRoleBinding, manifest.ClusterRoleBindingReplace{ Namespace: utils.DefaultNamespace, }) if err != nil { - return fmt.Errorf("(cluster rbac) kosmosctl join run error, generate clusterrolebinding failed: %s", err) + return fmt.Errorf("kosmosctl join run error, generate clusterrolebinding failed: %s", err) } _, err = o.Client.RbacV1().ClusterRoleBindings().Create(context.TODO(), clusterRoleBinding, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster rbac) kosmosctl join run error, create clusterrolebinding failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create clusterrolebinding failed: %s", err) } + klog.Info("ClusterRoleBinding: " + clusterRoleBinding.Name + " has been created.") // 5. create operator in member serviceAccount, err := util.GenerateServiceAccount(manifest.ClusterlinkOperatorServiceAccount, manifest.ServiceAccountReplace{ Namespace: utils.DefaultNamespace, }) if err != nil { - return fmt.Errorf("(cluster operator) kosmosctl join run error, generate serviceaccount failed: %s", err) + return fmt.Errorf("kosmosctl join run error, generate serviceaccount failed: %s", err) } _, err = o.Client.CoreV1().ServiceAccounts(serviceAccount.Namespace).Create(context.TODO(), serviceAccount, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster operator) kosmosctl join run error, create serviceaccount failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create serviceaccount failed: %s", err) } + klog.Info("ServiceAccount: " + serviceAccount.Name + " has been created.") deployment, err := util.GenerateDeployment(manifest.ClusterlinkOperatorDeployment, manifest.ClusterlinkDeploymentReplace{ Namespace: utils.DefaultNamespace, Version: version.GetReleaseVersion().PatchRelease(), - ClusterName: o.ClusterName, + ClusterName: o.Name, UseProxy: o.UseProxy, ImageRepository: o.ImageRegistry, }) if err != nil { - return fmt.Errorf("(cluster operator) kosmosctl join run error, generate deployment failed: %s", err) + return fmt.Errorf("kosmosctl join run error, generate deployment failed: %s", err) } _, err = o.Client.AppsV1().Deployments(deployment.Namespace).Create(context.TODO(), deployment, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(cluster operator) kosmosctl join run error, create deployment failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create deployment failed: %s", err) } - if err = util.WaitDeploymentReady(o.Client, deployment, o.WaitTime); err != nil { - return fmt.Errorf("(cluster operator) kosmosctl join run error, create deployment failed: %s", err) + label := map[string]string{"app": deployment.Labels["app"]} + if err = util.WaitPodReady(o.Client, deployment.Namespace, util.MapToString(label), o.WaitTime); err != nil { + return fmt.Errorf("kosmosctl join run error, create deployment failed: %s", err) } else { - klog.Info("Cluster registration successful.") + klog.Info("Deployment: " + deployment.Name + " has been created.") + klog.Info("Cluster [" + o.Name + "] registration successful.") } return nil @@ -286,11 +295,11 @@ func (o *CommandJoinOptions) runKnode() error { klog.Info("Start registering knode to kosmos control plane...") clusterKubeConfigByte, err := os.ReadFile(o.ClusterKubeConfig) if err != nil { - return fmt.Errorf("(knode) kosmosctl join run error, decode knode cr failed: %s", err) + return fmt.Errorf("kosmosctl join run error, decode knode cr failed: %s", err) } base64ClusterKubeConfig := base64.StdEncoding.EncodeToString(clusterKubeConfigByte) knodeByte, err := util.GenerateCustomResource(manifest.KnodeCR, manifest.KnodeReplace{ - KnodeName: o.KnodeName, + KnodeName: o.Name, KnodeKubeConfig: base64ClusterKubeConfig, }) if err != nil { @@ -300,13 +309,14 @@ func (o *CommandJoinOptions) runKnode() error { obj := &unstructured.Unstructured{} _, _, err = decoder.Decode(knodeByte, nil, obj) if err != nil { - return fmt.Errorf("(knode) kosmosctl join run error, decode knode cr failed: %s", err) + return fmt.Errorf("kosmosctl join run error, decode knode cr failed: %s", err) } _, err = o.DynamicClient.Resource(util.KnodeGVR).Namespace("").Create(context.TODO(), obj, metav1.CreateOptions{}) if err != nil && !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("(knode) kosmosctl join run error, create knode failed: %s", err) + return fmt.Errorf("kosmosctl join run error, create knode failed: %s", err) } - klog.Info("Knode registration successful.") + klog.Info("Knode: " + obj.GetName() + " has been created.") + klog.Info("Knode [" + obj.GetName() + "] registration successful.") return nil } diff --git a/pkg/kosmosctl/uninstall/uninstall.go b/pkg/kosmosctl/uninstall/uninstall.go index 9e2d79b1c..c43405a67 100644 --- a/pkg/kosmosctl/uninstall/uninstall.go +++ b/pkg/kosmosctl/uninstall/uninstall.go @@ -148,7 +148,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { clusters, err = o.DynamicClient.Resource(util.ClusterGVR).List(context.TODO(), metav1.ListOptions{}) if err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl uninstall clusterlink run error, list cluster failed: %v", err) - } else if len(clusters.Items) > 0 { + } else if clusters != nil && len(clusters.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing cluster crd because cr instance exists") } else { clusterCRD, _ := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil) @@ -165,7 +165,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { clusternodes, err = o.DynamicClient.Resource(util.ClusterNodeGVR).List(context.TODO(), metav1.ListOptions{}) if err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl uninstall clusterlink run error, list clusternode failed: %v", err) - } else if len(clusternodes.Items) > 0 { + } else if clusternodes != nil && len(clusternodes.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing clusternode crd because cr instance exists") } else { clusternodeCRD, _ := util.GenerateCustomResourceDefinition(manifest.ClusterlinkClusterNode, nil) @@ -182,7 +182,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { nodeconfigs, err = o.DynamicClient.Resource(util.NodeConfigGVR).List(context.TODO(), metav1.ListOptions{}) if err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl uninstall clusterlink run error, list nodeconfig failed: %v", err) - } else if len(nodeconfigs.Items) > 0 { + } else if nodeconfigs != nil && len(nodeconfigs.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing nodeconfig crd because cr instance exists") } else { nodeConfigCRD, _ := util.GenerateCustomResourceDefinition(manifest.ClusterlinkNodeConfig, nil) @@ -246,7 +246,7 @@ func (o *CommandUninstallOptions) runClustertree() error { knodes, err = o.DynamicClient.Resource(util.KnodeGVR).List(context.TODO(), metav1.ListOptions{}) if err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl uninstall clustertree run error, list knode failed: %v", err) - } else if len(knodes.Items) > 0 { + } else if knodes != nil && len(knodes.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing knode crd because cr instance exists") } else { knodeCRD, _ := util.GenerateCustomResourceDefinition(manifest.ClusterTreeKnode, nil) diff --git a/pkg/kosmosctl/unjoin/unjoin.go b/pkg/kosmosctl/unjoin/unjoin.go index c1ad48c1e..56ac298a9 100644 --- a/pkg/kosmosctl/unjoin/unjoin.go +++ b/pkg/kosmosctl/unjoin/unjoin.go @@ -24,25 +24,23 @@ import ( var unjoinExample = templates.Examples(i18n.T(` # Unjoin cluster from Kosmos control plane in any cluster, e.g: - kosmosctl unjoin cluster --cluster-name=[cluster-name] --cluster-kubeconfig=[member-kubeconfig] --master-kubeconfig=[master-kubeconfig] + kosmosctl unjoin cluster --name=[cluster-name] --cluster-kubeconfig=[member-kubeconfig] --master-kubeconfig=[master-kubeconfig] # Unjoin cluster from Kosmos control plane in master cluster, e.g: - kosmosctl unjoin cluster --cluster-name=[cluster-name] --cluster-kubeconfig=[member-kubeconfig] + kosmosctl unjoin cluster --name=[cluster-name] --cluster-kubeconfig=[member-kubeconfig] # Unjoin knode from Kosmos control plane in any cluster, e.g: - kosmosctl unjoin knode --knode-name=[knode-name] --master-kubeconfig=[master-kubeconfig] + kosmosctl unjoin knode --name=[knode-name] --master-kubeconfig=[master-kubeconfig] # Unjoin knode from Kosmos control plane in master cluster, e.g: - kosmosctl unjoin knode --knode-name=[knode-name] + kosmosctl unjoin knode --name=[knode-name] `)) type CommandUnJoinOptions struct { MasterKubeConfig string ClusterKubeConfig string - ClusterName string - - KnodeName string + Name string Client kubernetes.Interface DynamicClient *dynamic.DynamicClient @@ -69,8 +67,7 @@ func NewCmdUnJoin(f ctlutil.Factory) *cobra.Command { cmd.Flags().StringVarP(&o.MasterKubeConfig, "master-kubeconfig", "", "", "Absolute path to the master kubeconfig file.") cmd.Flags().StringVarP(&o.ClusterKubeConfig, "cluster-kubeconfig", "", "", "Absolute path to the cluster kubeconfig file.") - cmd.Flags().StringVar(&o.ClusterName, "cluster-name", "", "Specify the name of the member cluster to unjoin.") - cmd.Flags().StringVar(&o.KnodeName, "knode-name", "", "Specify the name of the knode to unjoin.") + cmd.Flags().StringVar(&o.Name, "name", "", "Specify the name of the resource to unjoin.") return cmd } @@ -109,9 +106,13 @@ func (o *CommandUnJoinOptions) Complete(f ctlutil.Factory) error { } func (o *CommandUnJoinOptions) Validate(args []string) error { + if len(o.Name) == 0 { + return fmt.Errorf("kosmosctl unjoin validate error, resource name is not valid") + } + switch args[0] { case "cluster": - _, err := o.DynamicClient.Resource(util.ClusterGVR).Get(context.TODO(), o.ClusterName, metav1.GetOptions{}) + _, err := o.DynamicClient.Resource(util.ClusterGVR).Get(context.TODO(), o.Name, metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl unjoin validate warning, clsuter is not found: %s", err) @@ -119,7 +120,7 @@ func (o *CommandUnJoinOptions) Validate(args []string) error { return fmt.Errorf("kosmosctl unjoin validate error, get cluster failed: %s", err) } case "knode": - _, err := o.DynamicClient.Resource(util.KnodeGVR).Get(context.TODO(), o.KnodeName, metav1.GetOptions{}) + _, err := o.DynamicClient.Resource(util.KnodeGVR).Get(context.TODO(), o.Name, metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { return fmt.Errorf("kosmosctl unjoin validate warning, knode is not found: %s", err) @@ -152,15 +153,16 @@ func (o *CommandUnJoinOptions) runCluster() error { klog.Info("Start removing cluster from kosmos control plane...") // 1. delete cluster for { - err := o.DynamicClient.Resource(util.ClusterGVR).Namespace("").Delete(context.TODO(), o.ClusterName, metav1.DeleteOptions{}) + err := o.DynamicClient.Resource(util.ClusterGVR).Namespace("").Delete(context.TODO(), o.Name, metav1.DeleteOptions{}) if err != nil { if apierrors.IsNotFound(err) { break } - return fmt.Errorf("(cluster) kosmosctl unjoin run error, delete cluster failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete cluster failed: %s", err) } time.Sleep(3 * time.Second) } + klog.Info("Cluster: " + o.Name + " has been deleted.") // 2. delete operator clusterlinkOperatorDeployment, err := util.GenerateDeployment(manifest.ClusterlinkOperatorDeployment, nil) @@ -169,32 +171,39 @@ func (o *CommandUnJoinOptions) runCluster() error { } err = o.Client.AppsV1().Deployments(utils.DefaultNamespace).Delete(context.TODO(), clusterlinkOperatorDeployment.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(operator) kosmosctl unjoin run error, delete deployment failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete deployment failed: %s", err) } + klog.Info("Deployment: " + clusterlinkOperatorDeployment.Name + " has been deleted.") // 3. delete secret err = o.Client.CoreV1().Secrets(utils.DefaultNamespace).Delete(context.TODO(), utils.ControlPanelSecretName, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(secret) kosmosctl unjoin run error, delete secret failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete secret failed: %s", err) } + klog.Info("Secret: " + utils.ControlPanelSecretName + " has been deleted.") // 4. delete rbac err = o.Client.RbacV1().ClusterRoleBindings().Delete(context.TODO(), utils.ExternalIPPoolNamePrefix, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(rbac) kosmosctl unjoin run error, delete clusterrolebinding failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete clusterrolebinding failed: %s", err) } + klog.Info("ClusterRoleBinding: " + utils.ExternalIPPoolNamePrefix + " has been deleted.") + err = o.Client.RbacV1().ClusterRoles().Delete(context.TODO(), utils.ExternalIPPoolNamePrefix, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(rbac) kosmosctl unjoin run error, delete clusterrole failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete clusterrole failed: %s", err) } + klog.Info("ClusterRole: " + utils.ExternalIPPoolNamePrefix + " has been deleted.") + clusterlinkOperatorServiceAccount, err := util.GenerateServiceAccount(manifest.ClusterlinkOperatorServiceAccount, nil) if err != nil { return err } err = o.Client.CoreV1().ServiceAccounts(utils.DefaultNamespace).Delete(context.TODO(), clusterlinkOperatorServiceAccount.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(operator) kosmosctl unjoin run error, delete serviceaccout failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete serviceaccout failed: %s", err) } + klog.Info("ServiceAccount: " + clusterlinkOperatorServiceAccount.Name + " has been deleted.") // 5. If cluster is not the master, delete namespace clusterlinkNetworkManagerDeployment, err := util.GenerateDeployment(manifest.ClusterlinkNetworkManagerDeployment, nil) @@ -205,27 +214,27 @@ func (o *CommandUnJoinOptions) runCluster() error { if err != nil && apierrors.IsNotFound(err) { err = o.Client.CoreV1().Namespaces().Delete(context.TODO(), utils.DefaultNamespace, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("(namespace) kosmosctl unjoin run error, delete namespace failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete namespace failed: %s", err) } } - klog.Info("Cluster [" + o.ClusterName + "] was removed.") + klog.Info("Cluster [" + o.Name + "] is removed.") return nil } func (o *CommandUnJoinOptions) runKnode() error { klog.Info("Start removing knode from kosmos control plane...") for { - err := o.DynamicClient.Resource(util.KnodeGVR).Namespace("").Delete(context.TODO(), o.KnodeName, metav1.DeleteOptions{}) + err := o.DynamicClient.Resource(util.KnodeGVR).Namespace("").Delete(context.TODO(), o.Name, metav1.DeleteOptions{}) if err != nil { if apierrors.IsNotFound(err) { break } - return fmt.Errorf("(knode) kosmosctl unjoin run error, delete knode failed: %s", err) + return fmt.Errorf("kosmosctl unjoin run error, delete knode failed: %s", err) } time.Sleep(3 * time.Second) } - klog.Info("Knode [" + o.KnodeName + "] was removed.") + klog.Info("Knode [" + o.Name + "] is removed.") return nil } diff --git a/pkg/utils/constants.go b/pkg/utils/constants.go index 037b620c7..5cf238b74 100644 --- a/pkg/utils/constants.go +++ b/pkg/utils/constants.go @@ -8,7 +8,10 @@ const ( const ExternalIPPoolNamePrefix = "clusterlink" -const CNITypeCalico = "calico" +const ( + CNITypeCalico = "calico" + NetworkTypeP2P = "p2p" +) const ( ProxySecretName = "clusterlink-agent-proxy"