Skip to content

Commit

Permalink
Merge pull request openyurtio#206 from Peeknut/refactor
Browse files Browse the repository at this point in the history
refactor: the node convert/revert feature
  • Loading branch information
rambohe-ch authored Feb 8, 2021
2 parents 5813c1a + f69c7eb commit 09063d4
Show file tree
Hide file tree
Showing 12 changed files with 1,106 additions and 270 deletions.
5 changes: 1 addition & 4 deletions config/yurtctl-servant/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
FROM alpine:3.8

RUN mkdir -p /var/lib/openyurt
ADD setup_edgenode /var/lib/openyurt
FROM alpine:3.8
238 changes: 0 additions & 238 deletions config/yurtctl-servant/setup_edgenode

This file was deleted.

2 changes: 0 additions & 2 deletions hack/lib/release-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ function build_yurtctl_servant_image() {
esac
cat << EOF > $docker_file_path
FROM $base_image
RUN mkdir -p /var/lib/openyurt
ADD setup_edgenode /var/lib/openyurt
EOF
ln $servant_script_path $docker_build_path/setup_edgenode
docker build --no-cache -t $yurtctl_servant_image -f $docker_file_path $docker_build_path
Expand Down
27 changes: 18 additions & 9 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
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"
clusterinfophase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/clusterinfo"
nodeutil "k8s.io/kubernetes/pkg/controller/util/node"

"github.com/alibaba/openyurt/pkg/projectinfo"
"github.com/alibaba/openyurt/pkg/yurtctl/constants"
Expand Down Expand Up @@ -89,6 +91,8 @@ func NewConvertCmd() *cobra.Command {
},
}

cmd.AddCommand(NewConvertEdgeNodeCmd())

cmd.Flags().StringP("cloud-nodes", "c", "",
"The list of cloud nodes.(e.g. -c cloudnode1,cloudnode2)")
cmd.Flags().StringP("provider", "p", "minikube",
Expand Down Expand Up @@ -227,11 +231,23 @@ func (co *ConvertOptions) RunConvert() (err error) {
}
klog.V(4).Info("the server version is valid")

// 2. label nodes as cloud node or edge node
// 1.1. check the state of worker nodes
nodeLst, err := co.clientSet.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return
}
for _, node := range nodeLst.Items {
if !strutil.IsInStringLst(co.CloudNodes, node.GetName()) {
_, condition := nodeutil.GetNodeCondition(&node.Status, v1.NodeReady)
if condition == nil || condition.Status != v1.ConditionTrue {
klog.Errorf("Cannot do the convert, the status of worker node: %s is not 'Ready'.", node.Name)
return
}
}
}
klog.V(4).Info("the status of worker nodes are satisfied")

// 2. label nodes as cloud node or edge node
var edgeNodeNames []string
for _, node := range nodeLst.Items {
if strutil.IsInStringLst(co.CloudNodes, node.GetName()) {
Expand All @@ -243,14 +259,7 @@ func (co *ConvertOptions) RunConvert() (err error) {
}
continue
}
// label node as edge node
klog.Infof("mark %s as the edge-node", node.GetName())
edgeNodeNames = append(edgeNodeNames, node.GetName())
_, err = kubeutil.LabelNode(co.clientSet,
&node, projectinfo.GetEdgeWorkerLabelKey(), "true")
if err != nil {
return
}
}

// 3. deploy yurt controller manager
Expand Down Expand Up @@ -331,7 +340,7 @@ func (co *ConvertOptions) RunConvert() (err error) {
"joinToken": joinToken,
"pod_manifest_path": co.PodMainfestPath,
"kubeadm_conf_path": co.KubeadmConfPath,
}, edgeNodeNames); err != nil {
}, edgeNodeNames, true); err != nil {
klog.Errorf("fail to run ServantJobs: %s", err)
return
}
Expand Down
Loading

0 comments on commit 09063d4

Please sign in to comment.