Skip to content

Commit

Permalink
add DeleteYurthubSetting to revert (openyurtio#492)
Browse files Browse the repository at this point in the history
Co-authored-by: zhoulei5 <zhoulei5@lixiang.com>
  • Loading branch information
2 people authored and YRXING committed Oct 9, 2021
1 parent 8e8d6c0 commit ae0642e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 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
27 changes: 19 additions & 8 deletions pkg/yurtctl/util/edgenode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ limitations under the License.
package edgenode

const (
KubeletSvcPath = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
OpenyurtDir = "/var/lib/openyurt"
StaticPodPath = "/etc/kubernetes/manifests"
KubeCondfigPath = "/etc/kubernetes/kubelet.conf"
KubeCaFile = "/etc/kubernetes/pki/ca.crt"
YurthubYamlName = "yurt-hub.yaml"
KubeletConfName = "kubelet.conf"
KubeletSvcBackup = "%s.bk"
KubeletSvcPath = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
OpenyurtDir = "/var/lib/openyurt"
StaticPodPath = "/etc/kubernetes/manifests"
KubeCondfigPath = "/etc/kubernetes/kubelet.conf"
KubeCaFile = "/etc/kubernetes/pki/ca.crt"
YurthubYamlName = "yurt-hub.yaml"
YurthubComponentName = "yurt-hub"
YurthubNamespace = "kube-system"
YurthubCmName = "yurt-hub-cfg"
KubeletConfName = "kubelet.conf"
KubeletSvcBackup = "%s.bk"

Hostname = "/etc/hostname"
KubeletHostname = "--hostname-override=[^\"\\s]*"
Expand Down Expand Up @@ -159,4 +162,12 @@ subjects:
kind: Group
name: system:nodes
`
YurthubConfigMap = `
apiVersion: v1
kind: ConfigMap
metadata:
name: yurt-hub-cfg
namespace: kube-system
data:
cache_agents: ""`
)
42 changes: 42 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 @@ -214,5 +219,42 @@ func DeployYurthubSetting(client *kubernetes.Clientset) error {
return err
}

// 3. create the Configmap
if err := CreateConfigMapFromYaml(client,
"kube-system",
edgenode.YurthubConfigMap); err != nil {
return err
}

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(), edgenode.YurthubComponentName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s",
edgenode.YurthubComponentName, err)
}

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

// 3. remove the ConfigMap
if err := client.CoreV1().ConfigMaps(edgenode.YurthubNamespace).
Delete(context.Background(), edgenode.YurthubCmName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the configmap/%s: %s",
edgenode.YurthubCmName, err)
}

return nil
}

0 comments on commit ae0642e

Please sign in to comment.