Skip to content

Commit

Permalink
add DeleteYurthubSetting to revert
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoulei5 committed Sep 23, 2021
1 parent da69115 commit 43796c1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/yurtctl/cmd/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ func (ro *RevertOptions) RunRevert() (err error) {
return
}
klog.Info("complete removing yurt-hub and resetting kubelet service")

// 7.1. remove yut-hub k8s config, roleBinding role
err = kubeutil.DeleteYurthubSetting(ro.clientSet)
if err != nil {
klog.Error("DeleteYurthubSetting err: ", err)
return err
}
klog.Info("delete yurthub clusterrole and clusterrolebinding")

return
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/yurtctl/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (

YurtctlLockConfigMapName = "yurtctl-lock"

YurthubComponentName = "yurt-hub"

YurttunnelServerComponentName = "yurt-tunnel-server"
YurttunnelServerSvcName = "x-tunnel-server-svc"
YurttunnelServerInternalSvcName = "x-tunnel-server-internal-svc"
Expand Down
27 changes: 27 additions & 0 deletions pkg/yurtctl/util/kubernetes/apply_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ limitations under the License.
package kubernetes

import (
"context"
"fmt"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -216,3 +221,25 @@ func DeployYurthubSetting(client *kubernetes.Clientset) error {

return nil
}

// DeleteYurthubSetting rm settings for yurthub pod
func DeleteYurthubSetting(client *kubernetes.Clientset) error {

// 1. delete the ClusterRoleBinding
if err := client.RbacV1().ClusterRoleBindings().
Delete(context.Background(), constants.YurthubComponentName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s",
constants.YurthubComponentName, err)
}

// 2. delete the ClusterRole
if err := client.RbacV1().ClusterRoles().
Delete(context.Background(), constants.YurthubComponentName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the clusterrole/%s: %s",
constants.YurthubComponentName, err)
}

return nil
}

0 comments on commit 43796c1

Please sign in to comment.