From 40a49ab997eadd8708ceb37afd35fdda50a5961b Mon Sep 17 00:00:00 2001 From: Zhe Cheng <47743202+lonelyCZ@users.noreply.github.com> Date: Fri, 13 May 2022 14:21:02 +0800 Subject: [PATCH] Remove convert and revert command (#826) Signed-off-by: lonelyCZ <531187475@qq.com> --- pkg/yurtctl/cmd/cmd.go | 4 - pkg/yurtctl/cmd/convert/convert.go | 374 ------------- pkg/yurtctl/cmd/convert/options.go | 363 ------------- pkg/yurtctl/cmd/revert/revert.go | 492 ------------------ .../app/phases/kubelet/flags_windows.go | 7 +- 5 files changed, 5 insertions(+), 1235 deletions(-) delete mode 100644 pkg/yurtctl/cmd/convert/convert.go delete mode 100644 pkg/yurtctl/cmd/convert/options.go delete mode 100644 pkg/yurtctl/cmd/revert/revert.go diff --git a/pkg/yurtctl/cmd/cmd.go b/pkg/yurtctl/cmd/cmd.go index e3d1a94a5d9..41ec13c00ac 100644 --- a/pkg/yurtctl/cmd/cmd.go +++ b/pkg/yurtctl/cmd/cmd.go @@ -27,11 +27,9 @@ import ( "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/clusterinfo" - "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/convert" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/join" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/markautonomous" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/reset" - "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/revert" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/yurtinit" "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/yurttest" ) @@ -48,8 +46,6 @@ func NewYurtctlCommand() *cobra.Command { setVersion(cmds) // add kubeconfig to persistent flags cmds.PersistentFlags().String("kubeconfig", "", "The path to the kubeconfig file") - cmds.AddCommand(convert.NewConvertCmd()) - cmds.AddCommand(revert.NewRevertCmd()) cmds.AddCommand(markautonomous.NewMarkAutonomousCmd()) cmds.AddCommand(clusterinfo.NewClusterInfoCmd()) cmds.AddCommand(yurtinit.NewCmdInit()) diff --git a/pkg/yurtctl/cmd/convert/convert.go b/pkg/yurtctl/cmd/convert/convert.go deleted file mode 100644 index d19a7cb811a..00000000000 --- a/pkg/yurtctl/cmd/convert/convert.go +++ /dev/null @@ -1,374 +0,0 @@ -/* -Copyright 2020 The OpenYurt Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package convert - -import ( - "context" - "fmt" - "net" - "os" - "strconv" - "strings" - "time" - - "github.com/spf13/cobra" - batchv1 "k8s.io/api/batch/v1" - v1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - bootstrapapi "k8s.io/cluster-bootstrap/token/api" - "k8s.io/klog/v2" - - nodeservant "github.com/openyurtio/openyurt/pkg/node-servant" - "github.com/openyurtio/openyurt/pkg/preflight" - kubeadmapi "github.com/openyurtio/openyurt/pkg/yurtctl/kubernetes/kubeadm/app/phases/bootstraptoken/clusterinfo" - "github.com/openyurtio/openyurt/pkg/yurtctl/lock" - kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes" - strutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/strings" - "github.com/openyurtio/openyurt/pkg/yurthub/util" -) - -const ( - // defaultYurthubHealthCheckTimeout defines the default timeout for yurthub health check phase - defaultYurthubHealthCheckTimeout = 2 * time.Minute - - latestYurtHubImage = "openyurt/yurthub:latest" - latestYurtControllerManagerImage = "openyurt/yurt-controller-manager:latest" - latestNodeServantImage = "openyurt/node-servant:latest" - latestYurtTunnelServerImage = "openyurt/yurt-tunnel-server:latest" - latestYurtTunnelAgentImage = "openyurt/yurt-tunnel-agent:latest" - versionedYurtAppManagerImage = "openyurt/yurt-app-manager:v0.4.0" -) - -// ClusterConverter do the cluster convert job. -// During the conversion, the pre-check will be performed first, and -// the conversion will be performed only after the pre-check is passed. -type ClusterConverter struct { - ConvertOptions -} - -// NewConvertCmd generates a new convert command -func NewConvertCmd() *cobra.Command { - co := NewConvertOptions() - cmd := &cobra.Command{ - Use: "convert -c CLOUDNODES", - Short: "Converts the kubernetes cluster to a yurt cluster", - Run: func(cmd *cobra.Command, _ []string) { - if err := co.Complete(cmd.Flags()); err != nil { - klog.Errorf("Fail to complete the convert option: %s", err) - os.Exit(1) - } - if err := co.Validate(); err != nil { - klog.Errorf("Fail to validate convert option: %s", err) - os.Exit(1) - } - converter := NewClusterConverter(co) - if err := converter.PreflightCheck(); err != nil { - klog.Errorf("Fail to run pre-flight checks: %s", err) - os.Exit(1) - } - if err := converter.RunConvert(); err != nil { - klog.Errorf("Fail to convert the cluster: %s", err) - os.Exit(1) - } - }, - Args: cobra.NoArgs, - } - - setFlags(cmd) - return cmd -} - -// setFlags sets flags. -func setFlags(cmd *cobra.Command) { - cmd.Flags().StringP( - "cloud-nodes", "c", "", - "The list of cloud nodes.(e.g. -c cloudnode1,cloudnode2)", - ) - cmd.Flags().StringP( - "autonomous-nodes", "a", "", - "The list of nodes that will be marked as autonomous. If not set, all edge nodes will be marked as autonomous."+ - "(e.g. -a autonomousnode1,autonomousnode2)", - ) - cmd.Flags().String( - "yurt-tunnel-server-address", "", - "The yurt-tunnel-server address.", - ) - cmd.Flags().String( - "kubeadm-conf-path", "", - "The path to kubelet service conf that is used by kubelet component to join the cluster on the edge node.", - ) - cmd.Flags().StringP( - "provider", "p", "minikube", - "The provider of the original Kubernetes cluster.", - ) - cmd.Flags().Duration( - "yurthub-healthcheck-timeout", defaultYurthubHealthCheckTimeout, - "The timeout for yurthub health check.", - ) - cmd.Flags().Duration( - "wait-servant-job-timeout", kubeutil.DefaultWaitServantJobTimeout, - "The timeout for servant-job run check.") - cmd.Flags().String( - "ignore-preflight-errors", "", - "A list of checks whose errors will be shown as warnings. Example: 'NodeEdgeWorkerLabel,NodeAutonomy'.Value 'all' ignores errors from all checks.", - ) - cmd.Flags().BoolP( - "deploy-yurttunnel", "t", false, - "If set, yurttunnel will be deployed.", - ) - cmd.Flags().BoolP( - "enable-app-manager", "e", false, - "If set, yurtappmanager will be deployed.", - ) - cmd.Flags().String( - "system-architecture", "amd64", - "The system architecture of cloud nodes.", - ) - - cmd.Flags().String("yurthub-image", latestYurtHubImage, "The yurthub image.") - cmd.Flags().String("yurt-controller-manager-image", latestYurtControllerManagerImage, "The yurt-controller-manager image.") - cmd.Flags().String("node-servant-image", latestNodeServantImage, "The node-servant image.") - cmd.Flags().String("yurt-tunnel-server-image", latestYurtTunnelServerImage, "The yurt-tunnel-server image.") - cmd.Flags().String("yurt-tunnel-agent-image", latestYurtTunnelAgentImage, "The yurt-tunnel-agent image.") - cmd.Flags().String("yurt-app-manager-image", versionedYurtAppManagerImage, "The yurt-app-manager image.") -} - -func NewClusterConverter(co *ConvertOptions) *ClusterConverter { - return &ClusterConverter{ - *co, - } -} - -// preflightCheck executes preflight checks logic. -func (c *ClusterConverter) PreflightCheck() error { - fmt.Println("[preflight] Running pre-flight checks") - if err := preflight.RunConvertClusterChecks(c.ClientSet, c.IgnorePreflightErrors); err != nil { - return err - } - - fmt.Println("[preflight] Running node-servant-preflight-convert jobs to check on edge and cloud nodes. " + - "Job running may take a long time, and job failure will affect the execution of the next stage") - jobLst, err := c.generatePreflightJobs() - if err != nil { - return err - } - if err := preflight.RunNodeServantJobCheck(c.ClientSet, jobLst, c.WaitServantJobTimeout, kubeutil.CheckServantJobPeriod, c.IgnorePreflightErrors); err != nil { - return err - } - - return nil -} - -// RunConvert performs the conversion -func (c *ClusterConverter) RunConvert() (err error) { - if err = lock.AcquireLock(c.ClientSet); err != nil { - return - } - defer func() { - if releaseLockErr := lock.ReleaseLock(c.ClientSet); releaseLockErr != nil { - klog.Error(releaseLockErr) - } - }() - - nodeLst, err := c.ClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return - } - edgeNodeNames := getEdgeNodeNames(nodeLst, c.CloudNodes) - - fmt.Println("[runConvert] Label all nodes with edgeworker label, annotate all nodes with autonomy annotation") - for _, node := range nodeLst.Items { - isEdge := strutil.IsInStringLst(edgeNodeNames, node.Name) - isAuto := strutil.IsInStringLst(c.AutonomousNodes, node.Name) - if _, err = kubeutil.AddEdgeWorkerLabelAndAutonomyAnnotation(c.ClientSet, &node, - strconv.FormatBool(isEdge), strconv.FormatBool(isAuto)); err != nil { - return - } - } - - // deploy yurt controller manager - fmt.Println("[runConvert] Deploying yurt-controller-manager") - if err = kubeutil.DeployYurtControllerManager(c.ClientSet, c.YurtControllerManagerImage); err != nil { - return - } - - // deploy the yurttunnel if required - if c.DeployTunnel { - fmt.Println("[runConvert] Deploying yurt-tunnel-server and yurt-tunnel-agent") - var certIP string - if c.YurttunnelServerAddress != "" { - certIP, _, _ = net.SplitHostPort(c.YurttunnelServerAddress) - } - if err = kubeutil.DeployYurttunnelServer(c.ClientSet, - certIP, - c.YurttunnelServerImage, - c.SystemArchitecture); err != nil { - return - } - // we will deploy yurt-tunnel-agent on every edge node - if err = kubeutil.DeployYurttunnelAgent(c.ClientSet, - c.YurttunnelServerAddress, - c.YurttunnelAgentImage); err != nil { - return - } - } - - // deploy the yurtappmanager if required - if c.EnableAppManager { - fmt.Println("[runConvert] Deploying yurt-app-manager") - if err = kubeutil.DeployYurtAppManager(c.ClientSet, - c.YurtAppManagerImage, - c.YurtAppManagerClientSet, - c.SystemArchitecture); err != nil { - return - } - } - - fmt.Println("[runConvert] Running jobs for convert. Job running may take a long time, and job failure will not affect the execution of the next stage") - - // disable node-controller - fmt.Println("[runConvert] Running disable-node-controller jobs to disable node-controller") - var kcmNodeNames []string - if kcmNodeNames, err = kubeutil.GetKubeControllerManagerHANodes(c.ClientSet); err != nil { - return - } - - if err = kubeutil.RunServantJobs(c.ClientSet, c.WaitServantJobTimeout, func(nodeName string) (*batchv1.Job, error) { - ctx := map[string]string{ - "node_servant_image": c.NodeServantImage, - "pod_manifest_path": c.PodMainfestPath, - } - return kubeutil.RenderServantJob("disable", ctx, nodeName) - }, kcmNodeNames, os.Stderr); err != nil { - return - } - - // deploy yurt-hub and reset the kubelet service on edge nodes. - fmt.Println("[runConvert] Running node-servant-convert jobs to deploy the yurt-hub and reset the kubelet service on edge and cloud nodes") - var joinToken string - if joinToken, err = prepareYurthubStart(c.ClientSet, c.KubeConfigPath); err != nil { - return - } - - convertCtx := map[string]string{ - "node_servant_image": c.NodeServantImage, - "yurthub_image": c.YurthubImage, - "joinToken": joinToken, - "kubeadm_conf_path": c.KubeadmConfPath, - "working_mode": string(util.WorkingModeEdge), - } - if c.YurthubHealthCheckTimeout != defaultYurthubHealthCheckTimeout { - convertCtx["yurthub_healthcheck_timeout"] = c.YurthubHealthCheckTimeout.String() - } - if len(edgeNodeNames) != 0 { - convertCtx["working_mode"] = string(util.WorkingModeEdge) - if err = kubeutil.RunServantJobs(c.ClientSet, c.WaitServantJobTimeout, func(nodeName string) (*batchv1.Job, error) { - return nodeservant.RenderNodeServantJob("convert", convertCtx, nodeName) - }, edgeNodeNames, os.Stderr); err != nil { - return - } - } - - // deploy yurt-hub and reset the kubelet service on cloud nodes - convertCtx["working_mode"] = string(util.WorkingModeCloud) - if err = kubeutil.RunServantJobs(c.ClientSet, c.WaitServantJobTimeout, func(nodeName string) (*batchv1.Job, error) { - return nodeservant.RenderNodeServantJob("convert", convertCtx, nodeName) - }, c.CloudNodes, os.Stderr); err != nil { - return - } - - fmt.Println("[runConvert] If any job fails, you can get job information through 'kubectl get jobs -n kube-system' to debug.\n" + - "\tNote that before the next conversion, please delete all related jobs so as not to affect the conversion.") - - return - -} - -func prepareYurthubStart(cliSet *kubernetes.Clientset, kcfg string) (string, error) { - // prepare kube-public/cluster-info configmap before convert - if err := prepareClusterInfoConfigMap(cliSet, kcfg); err != nil { - return "", err - } - - // prepare global settings(like RBAC, configmap) for yurthub - if err := kubeutil.DeployYurthubSetting(cliSet); err != nil { - return "", err - } - - // prepare join-token for yurthub - joinToken, err := kubeutil.GetOrCreateJoinTokenString(cliSet) - if err != nil || joinToken == "" { - return "", fmt.Errorf("fail to get join token: %v", err) - } - return joinToken, nil - -} - -// generatePreflightJobs generate preflight-check job for each node -func (c *ClusterConverter) generatePreflightJobs() ([]*batchv1.Job, error) { - jobLst := make([]*batchv1.Job, 0) - preflightCtx := map[string]string{ - "node_servant_image": c.NodeServantImage, - "kubeadm_conf_path": c.KubeadmConfPath, - "ignore_preflight_errors": strings.Join(c.IgnorePreflightErrors.List(), ","), - } - - nodeLst, err := c.ClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return nil, err - } - for _, node := range nodeLst.Items { - job, err := nodeservant.RenderNodeServantJob("preflight-convert", preflightCtx, node.Name) - if err != nil { - return nil, fmt.Errorf("fail to get job for node %s: %s", node.Name, err) - } - jobLst = append(jobLst, job) - } - - return jobLst, nil -} - -// prepareClusterInfoConfigMap will create cluster-info configmap in kube-public namespace if it does not exist -func prepareClusterInfoConfigMap(client *kubernetes.Clientset, file string) error { - info, err := client.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(context.Background(), bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{}) - if err != nil && apierrors.IsNotFound(err) { - // Create the cluster-info ConfigMap with the associated RBAC rules - if err := kubeadmapi.CreateBootstrapConfigMapIfNotExists(client, file); err != nil { - return fmt.Errorf("error creating bootstrap ConfigMap, %v", err) - } - if err := kubeadmapi.CreateClusterInfoRBACRules(client); err != nil { - return fmt.Errorf("error creating clusterinfo RBAC rules, %v", err) - } - } else if err != nil || info == nil { - return fmt.Errorf("fail to get configmap, %v", err) - } else { - klog.V(4).Infof("%s/%s configmap already exists, skip to prepare it", info.Namespace, info.Name) - } - - return nil -} - -func getEdgeNodeNames(nodeLst *v1.NodeList, cloudNodeNames []string) (edgeNodeNames []string) { - for _, node := range nodeLst.Items { - if !strutil.IsInStringLst(cloudNodeNames, node.GetName()) { - edgeNodeNames = append(edgeNodeNames, node.GetName()) - } - } - return -} diff --git a/pkg/yurtctl/cmd/convert/options.go b/pkg/yurtctl/cmd/convert/options.go deleted file mode 100644 index fb5f76d9e75..00000000000 --- a/pkg/yurtctl/cmd/convert/options.go +++ /dev/null @@ -1,363 +0,0 @@ -/* -Copyright 2021 The OpenYurt Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package convert - -import ( - "context" - "fmt" - "net" - "strings" - "time" - - "github.com/spf13/pflag" - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/kubernetes" - - enutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/edgenode" - kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes" - strutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/strings" -) - -// Provider signifies the provider type -type Provider string - -const ( - // ProviderMinikube is used if the target kubernetes is run on minikube - ProviderMinikube Provider = "minikube" - // ProviderACK is used if the target kubernetes is run on ack - ProviderACK Provider = "ack" - ProviderKubeadm Provider = "kubeadm" - // ProviderKind is used if the target kubernetes is run on kind - ProviderKind Provider = "kind" - - Amd64 string = "amd64" - Arm64 string = "arm64" - Arm string = "arm" -) - -// ConvertOptions has the information that required by convert operation -type ConvertOptions struct { - CloudNodes []string - // AutonomousNodes stores the names of edge nodes that are going to be marked as autonomous. - // If empty, all edge nodes will be marked as autonomous. - AutonomousNodes []string - YurttunnelServerAddress string - KubeConfigPath string - KubeadmConfPath string - Provider Provider - YurthubHealthCheckTimeout time.Duration - WaitServantJobTimeout time.Duration - IgnorePreflightErrors sets.String - DeployTunnel bool - EnableAppManager bool - - SystemArchitecture string - YurthubImage string - YurtControllerManagerImage string - NodeServantImage string - YurttunnelServerImage string - YurttunnelAgentImage string - YurtAppManagerImage string - - PodMainfestPath string - ClientSet *kubernetes.Clientset - YurtAppManagerClientSet dynamic.Interface -} - -// NewConvertOptions creates a new ConvertOptions -func NewConvertOptions() *ConvertOptions { - return &ConvertOptions{ - CloudNodes: []string{}, - AutonomousNodes: []string{}, - IgnorePreflightErrors: sets.NewString(), - } -} - -// Complete completes all the required options -func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error { - cnStr, err := flags.GetString("cloud-nodes") - if err != nil { - return err - } - if cnStr != "" { - co.CloudNodes = strings.Split(cnStr, ",") - } - - anStr, err := flags.GetString("autonomous-nodes") - if err != nil { - return err - } - if anStr != "" { - co.AutonomousNodes = strings.Split(anStr, ",") - } - - ytsa, err := flags.GetString("yurt-tunnel-server-address") - if err != nil { - return err - } - co.YurttunnelServerAddress = ytsa - - kcp, err := flags.GetString("kubeadm-conf-path") - if err != nil { - return err - } - co.KubeadmConfPath = kcp - - pStr, err := flags.GetString("provider") - if err != nil { - return err - } - co.Provider = Provider(pStr) - - yurthubHealthCheckTimeout, err := flags.GetDuration("yurthub-healthcheck-timeout") - if err != nil { - return err - } - co.YurthubHealthCheckTimeout = yurthubHealthCheckTimeout - - waitServantJobTimeout, err := flags.GetDuration("wait-servant-job-timeout") - if err != nil { - return err - } - co.WaitServantJobTimeout = waitServantJobTimeout - - ipStr, err := flags.GetString("ignore-preflight-errors") - if err != nil { - return err - } - if ipStr != "" { - ipStr = strings.ToLower(ipStr) - co.IgnorePreflightErrors = sets.NewString(strings.Split(ipStr, ",")...) - } - - dt, err := flags.GetBool("deploy-yurttunnel") - if err != nil { - return err - } - co.DeployTunnel = dt - - eam, err := flags.GetBool("enable-app-manager") - if err != nil { - return err - } - co.EnableAppManager = eam - - sa, err := flags.GetString("system-architecture") - if err != nil { - return err - } - co.SystemArchitecture = sa - - yhi, err := flags.GetString("yurthub-image") - if err != nil { - return err - } - co.YurthubImage = yhi - - ycmi, err := flags.GetString("yurt-controller-manager-image") - if err != nil { - return err - } - co.YurtControllerManagerImage = ycmi - - nsi, err := flags.GetString("node-servant-image") - if err != nil { - return err - } - co.NodeServantImage = nsi - - ytsi, err := flags.GetString("yurt-tunnel-server-image") - if err != nil { - return err - } - co.YurttunnelServerImage = ytsi - - ytai, err := flags.GetString("yurt-tunnel-agent-image") - if err != nil { - return err - } - co.YurttunnelAgentImage = ytai - - yami, err := flags.GetString("yurt-app-manager-image") - if err != nil { - return err - } - co.YurtAppManagerImage = yami - - // prepare path of cluster kubeconfig file - co.KubeConfigPath, err = kubeutil.PrepareKubeConfigPath(flags) - if err != nil { - return err - } - - co.PodMainfestPath = enutil.GetPodManifestPath() - - // parse kubeconfig and generate the clientset - co.ClientSet, err = kubeutil.GenClientSet(flags) - if err != nil { - return err - } - - // parse kubeconfig and generate the yurtappmanagerclientset - co.YurtAppManagerClientSet, err = kubeutil.GenDynamicClientSet(flags) - if err != nil { - return err - } - - return nil -} - -// Validate makes sure provided values for ConvertOptions are valid -func (co *ConvertOptions) Validate() error { - if err := ValidateKubeConfig(co.KubeConfigPath); err != nil { - return err - } - - if err := kubeutil.ValidateServerVersion(co.ClientSet); err != nil { - return err - } - - nodeLst, err := co.ClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return err - } - if err := ValidateCloudNodes(co.CloudNodes, nodeLst); err != nil { - return err - } - - edgeNodeNames := getEdgeNodeNames(nodeLst, co.CloudNodes) - if err := ValidateNodeAutonomy(edgeNodeNames, co.AutonomousNodes); err != nil { - return err - } - // If empty, mark all edge nodes as autonomous - if len(co.AutonomousNodes) == 0 { - co.AutonomousNodes = make([]string, len(edgeNodeNames)) - copy(co.AutonomousNodes, edgeNodeNames) - } - - if err := ValidateYurttunnelServerAddress(co.YurttunnelServerAddress); err != nil { - return err - } - if err := ValidateProvider(co.Provider); err != nil { - return err - } - if err := ValidateYurtHubHealthCheckTimeout(co.YurthubHealthCheckTimeout); err != nil { - return err - } - if err := ValidateWaitServantJobTimeout(co.WaitServantJobTimeout); err != nil { - return err - } - if err := ValidateIgnorePreflightErrors(co.IgnorePreflightErrors); err != nil { - return err - } - if err := ValidateSystemArchitecture(co.SystemArchitecture); err != nil { - return err - } - - return nil -} - -func ValidateCloudNodes(cloudNodeNames []string, nodeLst *v1.NodeList) error { - if cloudNodeNames == nil || len(cloudNodeNames) == 0 { - return fmt.Errorf("invalid --cloud-nodes: cannot be empty, please specify the cloud nodes") - } - - var notExistNodeNames []string - nodeNameSet := make(map[string]struct{}) - for _, node := range nodeLst.Items { - nodeNameSet[node.GetName()] = struct{}{} - } - for _, name := range cloudNodeNames { - if _, ok := nodeNameSet[name]; !ok { - notExistNodeNames = append(notExistNodeNames, name) - } - } - if len(notExistNodeNames) != 0 { - return fmt.Errorf("invalid --cloud-nodes: the nodes %v are not kubernetes node, can't be converted to cloud node", notExistNodeNames) - } - return nil -} - -func ValidateNodeAutonomy(edgeNodeNames []string, autonomousNodeNames []string) error { - var invaildation []string - for _, name := range autonomousNodeNames { - if !strutil.IsInStringLst(edgeNodeNames, name) { - invaildation = append(invaildation, name) - } - } - if len(invaildation) != 0 { - return fmt.Errorf("invalid --autonomous-nodes: can't make unedge nodes %v autonomous", invaildation) - } - return nil -} - -func ValidateProvider(provider Provider) error { - if provider != ProviderMinikube && provider != ProviderACK && - provider != ProviderKubeadm && provider != ProviderKind { - return fmt.Errorf("invalid --provider: %s, valid providers are: minikube, ack, kubeadm, kind", - provider) - } - return nil -} - -func ValidateYurttunnelServerAddress(address string) error { - if address != "" { - if _, _, err := net.SplitHostPort(address); err != nil { - return fmt.Errorf("invalid --yurt-tunnel-server-address: %s", err) - } - } - return nil -} - -func ValidateSystemArchitecture(arch string) error { - if arch != Amd64 && arch != Arm64 && arch != Arm { - return fmt.Errorf("invalid --system-architecture: %s, valid arch are: amd64, arm64, arm", arch) - } - return nil -} - -func ValidateIgnorePreflightErrors(ignoreErrors sets.String) error { - if ignoreErrors.Has("all") && ignoreErrors.Len() > 1 { - return fmt.Errorf("invalid --ignore-preflight-errors: please don't specify individual checks if 'all' is used in option 'ignorePreflightErrors'") - } - return nil -} - -func ValidateKubeConfig(kbCfgPath string) error { - if _, err := enutil.FileExists(kbCfgPath); err != nil { - return fmt.Errorf("invalid kubeconfig path: %v", err) - } - return nil - -} - -func ValidateYurtHubHealthCheckTimeout(t time.Duration) error { - if t <= 0 { - return fmt.Errorf("invalid --yurthub-healthcheck-timeout: time must be a valid number(greater than 0)") - } - return nil -} - -func ValidateWaitServantJobTimeout(t time.Duration) error { - if t <= 0 { - return fmt.Errorf("invalid --wait-servant-job-timeout: time must be a valid number(greater than 0)") - } - return nil -} diff --git a/pkg/yurtctl/cmd/revert/revert.go b/pkg/yurtctl/cmd/revert/revert.go deleted file mode 100644 index 7075408c833..00000000000 --- a/pkg/yurtctl/cmd/revert/revert.go +++ /dev/null @@ -1,492 +0,0 @@ -/* -Copyright 2020 The OpenYurt Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package revert - -import ( - "context" - "fmt" - "os" - "time" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" - batchv1 "k8s.io/api/batch/v1" - v1 "k8s.io/api/core/v1" - 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" - "k8s.io/klog/v2" - - nodeutil "github.com/openyurtio/openyurt/pkg/controller/util/node" - nodeservant "github.com/openyurtio/openyurt/pkg/node-servant" - "github.com/openyurtio/openyurt/pkg/projectinfo" - "github.com/openyurtio/openyurt/pkg/yurtctl/constants" - "github.com/openyurtio/openyurt/pkg/yurtctl/lock" - enutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/edgenode" - kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes" - tunneldns "github.com/openyurtio/openyurt/pkg/yurttunnel/trafficforward/dns" -) - -// RevertOptions has the information required by the revert operation -type RevertOptions struct { - clientSet *kubernetes.Clientset - waitServantJobTimeout time.Duration - NodeServantImage string - PodMainfestPath string - KubeadmConfPath string - yurtAppManagerClientSet dynamic.Interface -} - -// NewRevertOptions creates a new RevertOptions -func NewRevertOptions() *RevertOptions { - return &RevertOptions{} -} - -// NewRevertCmd generates a new revert command -func NewRevertCmd() *cobra.Command { - ro := NewRevertOptions() - cmd := &cobra.Command{ - Use: "revert", - Short: "Reverts the yurt cluster back to a Kubernetes cluster", - Run: func(cmd *cobra.Command, _ []string) { - if err := ro.Complete(cmd.Flags()); err != nil { - klog.Errorf("fail to complete the revert option: %s", err) - os.Exit(1) - } - if err := ro.RunRevert(); err != nil { - klog.Errorf("fail to revert yurt to kubernetes: %s", err) - os.Exit(1) - } - }, - Args: cobra.NoArgs, - } - - cmd.Flags().String("node-servant-image", - "openyurt/node-servant:latest", - "The node-servant image.") - cmd.Flags().String("kubeadm-conf-path", - "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf", - "The path to kubelet service conf that is used by kubelet component to join the cluster on the edge node.") - cmd.Flags().Duration("wait-servant-job-timeout", kubeutil.DefaultWaitServantJobTimeout, - "The timeout for servant-job run check.") - return cmd -} - -// Complete completes all the required options -func (ro *RevertOptions) Complete(flags *pflag.FlagSet) error { - nsi, err := flags.GetString("node-servant-image") - if err != nil { - return err - } - ro.NodeServantImage = nsi - - kcp, err := flags.GetString("kubeadm-conf-path") - if err != nil { - return err - } - ro.KubeadmConfPath = kcp - - ro.PodMainfestPath = enutil.GetPodManifestPath() - - waitServantJobTimeout, err := flags.GetDuration("wait-servant-job-timeout") - if err != nil { - return err - } - ro.waitServantJobTimeout = waitServantJobTimeout - - ro.clientSet, err = kubeutil.GenClientSet(flags) - if err != nil { - return err - } - - ro.yurtAppManagerClientSet, err = kubeutil.GenDynamicClientSet(flags) - if err != nil { - return err - } - return nil -} - -// RunRevert reverts the target Yurt cluster back to a standard Kubernetes cluster -func (ro *RevertOptions) RunRevert() (err error) { - if err = lock.AcquireLock(ro.clientSet); err != nil { - return - } - defer func() { - if deleteLockErr := lock.DeleteLock(ro.clientSet); deleteLockErr != nil { - klog.Error(deleteLockErr) - } - }() - klog.V(4).Info("successfully acquire the lock") - - // 1. check the server version - if err = kubeutil.ValidateServerVersion(ro.clientSet); err != nil { - return - } - klog.V(4).Info("the server version is valid") - - // 1.1. get kube-controller-manager HA nodes - kcmNodeNames, err := kubeutil.GetKubeControllerManagerHANodes(ro.clientSet) - if err != nil { - return - } - - // 1.2. check the state of all nodes - nodeLst, err := ro.clientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return - } - - var nodeNames []string - for _, node := range nodeLst.Items { - if !isNodeReady(&node.Status) { - return fmt.Errorf("cannot do the revert, the status of worker or kube-controller-manager node: %s is not 'Ready'", node.Name) - } - nodeNames = append(nodeNames, node.GetName()) - } - klog.V(4).Info("the status of all nodes are satisfied") - - // 2. remove the yurt controller manager - if err = ro.clientSet.AppsV1().Deployments(constants.YurtAppManagerNamespace). - Delete(context.Background(), constants.YurtControllerManager, metav1.DeleteOptions{ - PropagationPolicy: &kubeutil.PropagationPolicy, - }); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to remove yurt controller manager: %s", err) - } - klog.Info("yurt controller manager is removed") - - // 2.1 remove the serviceaccount for yurt-controller-manager - if err = ro.clientSet.CoreV1().ServiceAccounts(constants.YurtAppManagerNamespace). - Delete(context.Background(), constants.YurtControllerManager, metav1.DeleteOptions{ - PropagationPolicy: &kubeutil.PropagationPolicy, - }); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to remove serviceaccount for yurt controller manager: %s", err) - } - klog.Info("serviceaccount for yurt controller manager is removed") - - // 2.2 remove the clusterrole for yurt-controller-manager - if err = ro.clientSet.RbacV1().ClusterRoles(). - Delete(context.Background(), constants.YurtControllerManager, metav1.DeleteOptions{ - PropagationPolicy: &kubeutil.PropagationPolicy, - }); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to remove clusterrole for yurt controller manager: %s", err) - } - klog.Info("clusterrole for yurt controller manager is removed") - - // 2.3 remove the clusterrolebinding for yurt-controller-manager - if err = ro.clientSet.RbacV1().ClusterRoleBindings(). - Delete(context.Background(), constants.YurtControllerManager, metav1.DeleteOptions{ - PropagationPolicy: &kubeutil.PropagationPolicy, - }); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to remove clusterrolebinding for yurt controller manager: %s", err) - } - klog.Info("clusterrolebinding for yurt controller manager is removed") - - // 3. remove the yurt-tunnel agent - if err = removeYurtTunnelAgent(ro.clientSet); err != nil { - return fmt.Errorf("fail to remove the yurt tunnel agent: %s", err) - } - - // 4. remove the yurt-tunnel server - if err = removeYurtTunnelServer(ro.clientSet); err != nil { - return fmt.Errorf("fail to remove the yurt tunnel server: %s", err) - } - - // 5. remove the yurt app manager - if err = removeYurtAppManager(ro.clientSet, ro.yurtAppManagerClientSet); err != nil { - return fmt.Errorf("fail to remove the yurt app manager: %s", err) - } - klog.Info("yurt app manager is removed") - - // 6. enable node-controller - if err = kubeutil.RunServantJobs(ro.clientSet, ro.waitServantJobTimeout, - func(nodeName string) (*batchv1.Job, error) { - ctx := map[string]string{ - "node_servant_image": ro.NodeServantImage, - "pod_manifest_path": ro.PodMainfestPath, - } - return kubeutil.RenderServantJob("enable", ctx, nodeName) - }, - kcmNodeNames, os.Stderr); err != nil { - return fmt.Errorf("fail to run EnableNodeControllerJobs: %s", err) - } - klog.Info("complete enabling node-controller") - - // 7. remove yurt-hub and revert kubelet service on edge nodes - if err = kubeutil.RunServantJobs(ro.clientSet, ro.waitServantJobTimeout, func(nodeName string) (*batchv1.Job, error) { - ctx := map[string]string{ - "node_servant_image": ro.NodeServantImage, - "kubeadm_conf_path": ro.KubeadmConfPath, - } - return nodeservant.RenderNodeServantJob("revert", ctx, nodeName) - }, nodeNames, os.Stderr); err != nil { - klog.Errorf("fail to revert node: %s", err) - return - } - klog.Info("complete removing yurt-hub and resetting kubelet service") - - // 8. remove yut-hub k8s config, roleBinding role - err = kubeutil.DeleteYurthubSetting(ro.clientSet) - if err != nil { - return fmt.Errorf("fail to delete yurthub setting: %s", err) - } - klog.Info("delete yurthub clusterrole and clusterrolebinding") - - // 9. remove label and annotation of nodes - nodeLst, err = ro.clientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return - } - for _, node := range nodeLst.Items { - _, foundAutonomy := node.Annotations[constants.AnnotationAutonomy] - if foundAutonomy { - delete(node.Annotations, constants.AnnotationAutonomy) - } - delete(node.Labels, projectinfo.GetEdgeWorkerLabelKey()) - if _, err = ro.clientSet.CoreV1().Nodes().Update(context.Background(), &node, metav1.UpdateOptions{}); err != nil { - return fmt.Errorf("fail to remove label or annotation for node: %s: %s", node.GetName(), err) - } - klog.Infof("label %s is removed from node %s", projectinfo.GetEdgeWorkerLabelKey(), node.GetName()) - if foundAutonomy { - klog.Infof("annotation %s is removed from node %s", constants.AnnotationAutonomy, node.GetName()) - } - } - - return -} - -func removeYurtTunnelServer(client *kubernetes.Clientset) error { - // 1. remove the DaemonSet - if err := client.AppsV1(). - Deployments(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelServerComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the daemonset/%s: %s", - constants.YurttunnelServerComponentName, err) - } - klog.V(4).Infof("deployment/%s is deleted", constants.YurttunnelServerComponentName) - - // 2.1 remove the Service - if err := client.CoreV1().Services(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelServerSvcName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the service/%s: %s", - constants.YurttunnelServerSvcName, err) - } - klog.V(4).Infof("service/%s is deleted", constants.YurttunnelServerSvcName) - - // 2.2 remove the internal Service(type=ClusterIP) - if err := client.CoreV1().Services(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelServerInternalSvcName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the service/%s: %s", - constants.YurttunnelServerInternalSvcName, err) - } - klog.V(4).Infof("service/%s is deleted", constants.YurttunnelServerInternalSvcName) - - // 3. remove the ClusterRoleBinding - if err := client.RbacV1().ClusterRoleBindings(). - Delete(context.Background(), constants.YurttunnelServerComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s", - constants.YurttunnelServerComponentName, err) - } - klog.V(4).Infof("clusterrolebinding/%s is deleted", constants.YurttunnelServerComponentName) - - // 4. remove the SerivceAccount - if err := client.CoreV1().ServiceAccounts(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelServerComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the serviceaccount/%s: %s", - constants.YurttunnelServerComponentName, err) - } - klog.V(4).Infof("serviceaccount/%s is deleted", constants.YurttunnelServerComponentName) - - // 5. remove the ClusterRole - if err := client.RbacV1().ClusterRoles(). - Delete(context.Background(), constants.YurttunnelServerComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrole/%s: %s", - constants.YurttunnelServerComponentName, err) - } - klog.V(4).Infof("clusterrole/%s is deleted", constants.YurttunnelServerComponentName) - - // 6. remove the yurt-tunnel-server-cfg - if err := client.CoreV1().ConfigMaps(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelServerCmName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the configmap/%s: %s", - constants.YurttunnelServerCmName, err) - } - - // 7. remove the dns record configmap - yurttunnelDnsRecordConfigMapName := tunneldns.GetYurtTunnelDNSRecordConfigMapName() - if err := client.CoreV1().ConfigMaps(constants.YurttunnelNamespace). - Delete(context.Background(), yurttunnelDnsRecordConfigMapName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete configmap/%s: %s", - yurttunnelDnsRecordConfigMapName, err) - } - - return nil -} - -func removeYurtAppManager(client *kubernetes.Clientset, yurtAppManagerClientSet dynamic.Interface) error { - // 1. remove the Deployment - if err := client.AppsV1(). - Deployments(constants.YurtAppManagerNamespace). - Delete(context.Background(), constants.YurtAppManager, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the deployment/%s: %s", - constants.YurtAppManager, err) - } - klog.Info("deployment for yurt app manager is removed") - klog.V(4).Infof("deployment/%s is deleted", constants.YurtAppManager) - - // 2. remove the Role - if err := client.RbacV1().Roles(constants.YurtAppManagerNamespace). - Delete(context.Background(), "yurt-app-leader-election-role", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the role/%s: %s", - "yurt-app-leader-election-role", err) - } - klog.Info("Role for yurt app manager is removed") - - // 3. remove the ClusterRole - if err := client.RbacV1().ClusterRoles(). - Delete(context.Background(), "yurt-app-manager-role", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrole/%s: %s", - "yurt-app-manager-role", err) - } - klog.Info("ClusterRole for yurt app manager is removed") - - // 4. remove the ClusterRoleBinding - if err := client.RbacV1().ClusterRoleBindings(). - Delete(context.Background(), "yurt-app-manager-rolebinding", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s", - "yurt-app-manager-rolebinding", err) - } - klog.Info("ClusterRoleBinding for yurt app manager is removed") - klog.V(4).Infof("clusterrolebinding/%s is deleted", "yurt-app-manager-rolebinding") - - // 5. remove the RoleBinding - if err := client.RbacV1().RoleBindings(constants.YurtAppManagerNamespace). - Delete(context.Background(), "yurt-app-leader-election-rolebinding", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the rolebinding/%s: %s", - "yurt-app-leader-election-rolebinding", err) - } - klog.Info("RoleBinding for yurt app manager is removed") - klog.V(4).Infof("clusterrolebinding/%s is deleted", "yurt-app-leader-election-rolebinding") - - // 6 remove the Secret - if err := client.CoreV1().Secrets(constants.YurtAppManagerNamespace). - Delete(context.Background(), "yurt-app-webhook-certs", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the secret/%s: %s", - "yurt-app-webhook-certs", err) - } - klog.Info("secret for yurt app manager is removed") - klog.V(4).Infof("secret/%s is deleted", "yurt-app-webhook-certs") - - // 7 remove Service - if err := client.CoreV1().Services(constants.YurtAppManagerNamespace). - Delete(context.Background(), "yurt-app-webhook-service", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the service/%s: %s", - "yurt-app-webhook-service", err) - } - klog.Info("Service for yurt app manager is removed") - klog.V(4).Infof("service/%s is deleted", "yurt-app-webhook-service") - - // 8. remove the MutatingWebhookConfiguration - if err := client.AdmissionregistrationV1beta1().MutatingWebhookConfigurations(). - Delete(context.Background(), "yurt-app-mutating-webhook-configuration", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the MutatingWebhookConfiguration/%s: %s", - "yurt-app-mutating-webhook-configuration", err) - } - klog.Info("MutatingWebhookConfiguration for yurt app manager is removed") - klog.V(4).Infof("MutatingWebhookConfiguration/%s is deleted", "yurt-app-mutating-webhook-configuration") - - // 9. remove the ValidatingWebhookConfiguration - if err := client.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations(). - Delete(context.Background(), "yurt-app-validating-webhook-configuration", - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the ValidatingWebhookConfiguration/%s: %s", - "yurt-app-validating-webhook-configuration", err) - } - klog.Info("ValidatingWebhookConfiguration for yurt app manager is removed") - klog.V(4).Infof("ValidatingWebhookConfiguration/%s is deleted", "yurt-app-validating-webhook-configuration") - - // 10. remove nodepoolcrd - if err := kubeutil.DeleteCRDResource(client, yurtAppManagerClientSet, - "NodePool", "nodepools.apps.openyurt.io", []byte(constants.YurtAppManagerNodePool)); err != nil { - return fmt.Errorf("fail to delete the NodePoolCRD/%s: %s", - "nodepoolcrd", err) - } - klog.Info("crd for yurt app manager is removed") - klog.V(4).Infof("NodePoolCRD/%s is deleted", "NodePool") - - // 11. remove UnitedDeploymentcrd - if err := kubeutil.DeleteCRDResource(client, yurtAppManagerClientSet, - "UnitedDeployment", "uniteddeployments.apps.openyurt.io", []byte(constants.YurtAppManagerUnitedDeployment)); err != nil { - return fmt.Errorf("fail to delete the UnitedDeploymentCRD/%s: %s", - "UnitedDeployment", err) - } - klog.Info("UnitedDeploymentcrd for yurt app manager is removed") - klog.V(4).Infof("UnitedDeploymentCRD/%s is deleted", "UnitedDeployment") - return nil -} - -func removeYurtTunnelAgent(client *kubernetes.Clientset) error { - // 1. remove the DaemonSet - if err := client.AppsV1(). - DaemonSets(constants.YurttunnelNamespace). - Delete(context.Background(), constants.YurttunnelAgentComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the daemonset/%s: %s", - constants.YurttunnelAgentComponentName, err) - } - klog.V(4).Infof("daemonset/%s is deleted", constants.YurttunnelAgentComponentName) - - // 2. remove the ClusterRoleBinding - if err := client.RbacV1().ClusterRoleBindings(). - Delete(context.Background(), constants.YurttunnelAgentComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s", - constants.YurttunnelAgentComponentName, err) - } - klog.V(4).Infof("clusterrolebinding/%s is deleted", constants.YurttunnelAgentComponentName) - - // 3. remove the ClusterRole - if err := client.RbacV1().ClusterRoles(). - Delete(context.Background(), constants.YurttunnelAgentComponentName, - metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("fail to delete the clusterrole/%s: %s", - constants.YurttunnelAgentComponentName, err) - } - klog.V(4).Infof("clusterrole/%s is deleted", constants.YurttunnelAgentComponentName) - return nil -} - -func isNodeReady(status *v1.NodeStatus) bool { - _, condition := nodeutil.GetNodeCondition(status, v1.NodeReady) - return condition != nil && condition.Status == v1.ConditionTrue -} diff --git a/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags_windows.go b/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags_windows.go index 5300224cecc..00f8d0385cd 100644 --- a/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags_windows.go +++ b/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows /* @@ -18,8 +19,10 @@ limitations under the License. package kubelet +import "github.com/openyurtio/openyurt/pkg/yurtctl/cmd/join/joindata" + // buildKubeletArgMap takes a kubeletFlagsOpts object and builds based on that a string-string map with flags // that should be given to the local Windows kubelet daemon. -func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { - return buildKubeletArgMapCommon(opts) +func buildKubeletArgMap(data joindata.YurtJoinData) map[string]string { + return buildKubeletArgMapCommon(data) }