Skip to content

Commit

Permalink
cleanup: add finalizers for mcs to make code graceful
Browse files Browse the repository at this point in the history
Signed-off-by: duanmengkk <[email protected]>
  • Loading branch information
duanmengkk committed Dec 20, 2023
1 parent 36dbb37 commit db46893
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pkg/kosmosctl/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewCmdJoin(f ctlutil.Factory) *cobra.Command {
func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error {
hostConfig, err := utils.RestConfig(o.HostKubeConfig, o.HostContext)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate host rest config failed: %s", err)
return fmt.Errorf("kosmosctl join complete error, generate host rest config failed: %s", err)
}

if o.Version == "" {
Expand All @@ -123,23 +123,23 @@ func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error {

o.KosmosClient, err = versioned.NewForConfig(hostConfig)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate Kosmos client failed: %v", err)
return fmt.Errorf("kosmosctl join complete error, generate Kosmos client failed: %v", err)
}

if len(o.KubeConfig) > 0 {
clusterConfig, err := utils.RestConfig(o.KubeConfig, o.Context)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate rest config failed: %s", err)
return fmt.Errorf("kosmosctl join complete error, generate rest config failed: %s", err)
}

rawConfig, err := utils.RawConfig(o.KubeConfig, o.Context)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate raw config failed: %s", err)
return fmt.Errorf("kosmosctl join complete error, generate raw config failed: %s", err)
}

streams, err := clientcmd.Write(rawConfig)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate config streams failed: %s", err)
return fmt.Errorf("kosmosctl join complete error, wite restconfig to streams failed: %s", err)
}

o.KubeConfigStream = streams
Expand Down
6 changes: 3 additions & 3 deletions pkg/kosmosctl/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewCmdUninstall() *cobra.Command {
func (o *CommandUninstallOptions) Complete() error {
config, err := utils.RestConfig(o.KubeConfig, o.Context)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate config failed: %s", err)
return fmt.Errorf("kosmosctl uninstall complete error, generate config failed: %s", err)
}

if o.Version == "" {
Expand All @@ -93,7 +93,7 @@ func (o *CommandUninstallOptions) Complete() error {

o.KosmosClient, err = versioned.NewForConfig(config)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate Kosmos client failed: %v", err)
return fmt.Errorf("kosmosctl uninstall complete error, generate Kosmos client failed: %v", err)
}

o.K8sClient, err = kubernetes.NewForConfig(config)
Expand Down Expand Up @@ -510,7 +510,7 @@ func (o *CommandUninstallOptions) runCoredns() error {
}
err = o.K8sClient.RbacV1().ClusterRoles().Delete(context.TODO(), cRole.Name, metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("kosmosctl install coredns run error, clusterrole options failed: %v", err)
return fmt.Errorf("kosmosctl uninstall coredns run error, clusterrole options failed: %v", err)
}
klog.Info("ClusterRole " + cRole.Name + " is deleted.")

Expand Down
6 changes: 3 additions & 3 deletions pkg/kosmosctl/unjoin/unjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ func NewCmdUnJoin(f ctlutil.Factory) *cobra.Command {
func (o *CommandUnJoinOptions) Complete(f ctlutil.Factory) error {
hostConfig, err := utils.RestConfig(o.HostKubeConfig, o.HostContext)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate host config failed: %s", err)
return fmt.Errorf("kosmosctl unjoin complete error, generate host config failed: %s", err)
}

var clusterConfig *restclient.Config

o.KosmosClient, err = versioned.NewForConfig(hostConfig)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate Kosmos client failed: %v", err)
return fmt.Errorf("kosmosctl unjoin complete error, generate Kosmos client failed: %v", err)
}

if o.KubeConfig != "" {
clusterConfig, err = utils.RestConfig(o.KubeConfig, o.Context)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate config failed: %s", err)
return fmt.Errorf("kosmosctl unjoin complete error, generate config failed: %s", err)
}
} else {
var cluster *v1alpha1.Cluster
Expand Down

0 comments on commit db46893

Please sign in to comment.