diff --git a/config/yurtctl-servant/Dockerfile b/config/yurtctl-servant/Dockerfile index 1154c8492cd..4b5dbe5acd6 100644 --- a/config/yurtctl-servant/Dockerfile +++ b/config/yurtctl-servant/Dockerfile @@ -1 +1 @@ -FROM alpine:3.8 \ No newline at end of file +FROM ubuntu:20.04 \ No newline at end of file diff --git a/hack/lib/release-images.sh b/hack/lib/release-images.sh index b37183c4743..939db95b943 100755 --- a/hack/lib/release-images.sh +++ b/hack/lib/release-images.sh @@ -19,7 +19,7 @@ set -x YURT_IMAGE_DIR=${YURT_OUTPUT_DIR}/images YURTCTL_SERVANT_DIR=${YURT_ROOT}/config/yurtctl-servant DOCKER_BUILD_BASE_IDR=$YURT_ROOT/dockerbuild -YURT_BUILD_IMAGE="golang:1.13-alpine" +YURT_BUILD_IMAGE="golang:1.13-ubuntu" #REPO="openyurt" #TAG="v0.2.0" @@ -118,13 +118,13 @@ function build_yurtctl_servant_image() { local base_image case $arch in amd64) - base_image="amd64/alpine:3.9" + base_image="amd64/ubuntu:20.04" ;; arm64) - base_image="arm64v8/alpine:3.9" + base_image="arm64v8/ubuntu:20.04" ;; arm) - base_image="arm32v7/alpine:3.9" + base_image="arm32v7/ubuntu:20.04" ;; *) echo unknown arch $arch @@ -132,8 +132,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 diff --git a/pkg/yurtctl/cmd/convert/convert.go b/pkg/yurtctl/cmd/convert/convert.go index 10b02553882..a7eb137f8ad 100644 --- a/pkg/yurtctl/cmd/convert/convert.go +++ b/pkg/yurtctl/cmd/convert/convert.go @@ -317,6 +317,7 @@ func (co *ConvertOptions) RunConvert() (err error) { } if err = kubeutil.RunServantJobs(co.clientSet, map[string]string{ "provider": string(co.Provider), + "action": "convert", "yurtctl_servant_image": co.YurctlServantImage, "yurthub_image": co.YurhubImage, "joinToken": joinToken, diff --git a/pkg/yurtctl/cmd/convert/edgenode.go b/pkg/yurtctl/cmd/convert/edgenode.go index 08e351d289d..0241b9ae2de 100644 --- a/pkg/yurtctl/cmd/convert/edgenode.go +++ b/pkg/yurtctl/cmd/convert/edgenode.go @@ -17,7 +17,6 @@ import ( "k8s.io/klog" "github.com/alibaba/openyurt/pkg/projectinfo" - "github.com/alibaba/openyurt/pkg/yurtctl/lock" enutil "github.com/alibaba/openyurt/pkg/yurtctl/util/edgenode" kubeutil "github.com/alibaba/openyurt/pkg/yurtctl/util/kubernetes" "github.com/alibaba/openyurt/pkg/yurthub/healthchecker" @@ -25,12 +24,11 @@ import ( const ( kubeletConfigRegularExpression = "\\-\\-kubeconfig=.*kubelet.conf" - apiserverAddrRegularExpression = "server: (http(s)?:\\/\\/)?[\\d\\D][\\d\\D]{0,62}(\\.[\\d\\D][-\\d\\D]{0,62})+(:[\\d]{1,5})?$" - - hubHealthzCheckFrequency = 10 * time.Second - failedRetry = 5 - filemode = 0666 - dirmode = 0755 + apiserverAddrRegularExpression = "server: (http(s)?:\\/\\/)?[\\w][\\w]{0,62}(\\.[\\w][-\\w]{0,62})+(:[\\d]{1,5})?" + hubHealthzCheckFrequency = 10 * time.Second + failedRetry = 5 + filemode = 0666 + dirmode = 0755 ) // EdgenodeOptions holds the command-line options for 'convert edgenode' sub command @@ -109,16 +107,6 @@ func (c *ConvertEdgeNodeOptions) Complete(flags *pflag.FlagSet) error { } func (c *ConvertEdgeNodeOptions) RunConvertEdgeNode() (err error) { - if err = lock.AcquireLock(c.clientSet); err != nil { - return - } - defer func() { - if releaseLockErr := lock.ReleaseLock(c.clientSet); releaseLockErr != nil { - klog.Error(releaseLockErr) - } - }() - klog.V(4).Info("successfully acquire the lock") - // 1. check the server version if err = kubeutil.ValidateServerVersion(c.clientSet); err != nil { return @@ -219,7 +207,7 @@ func (c *ConvertEdgeNodeOptions) ResetKubelet() error { if err != nil { return err } - kubeConfigSetup := fmt.Sprintf("--kubeconfig=%s\\kubelet.conf", c.openyurtDir) + kubeConfigSetup := fmt.Sprintf("--kubeconfig=%s/kubelet.conf", c.openyurtDir) content := enutil.ReplaceRegularExpression(string(contentbyte), map[string]string{ "--bootstrap.*bootstrap-kubelet.conf": "", "--kubeconfig=.*kubelet.conf": kubeConfigSetup, @@ -235,13 +223,13 @@ func (c *ConvertEdgeNodeOptions) ResetKubelet() error { if err := cmd.Exec(); err != nil { return err } - fmt.Println(cmd.GetStdOut()) + klog.Info(cmd.GetStdOut()) cmd = enutil.NewCommand(enutil.RestartKubeletSvc) if err := cmd.Exec(); err != nil { return err } - fmt.Println(cmd.GetStdOut()) + klog.Info(cmd.GetStdOut()) klog.Infof("kubelet has been restarted") return nil } diff --git a/pkg/yurtctl/cmd/revert/edgenode.go b/pkg/yurtctl/cmd/revert/edgenode.go index 4c2769ba8ab..f6e12309c2f 100644 --- a/pkg/yurtctl/cmd/revert/edgenode.go +++ b/pkg/yurtctl/cmd/revert/edgenode.go @@ -15,7 +15,6 @@ import ( "github.com/alibaba/openyurt/pkg/projectinfo" "github.com/alibaba/openyurt/pkg/yurtctl/constants" - "github.com/alibaba/openyurt/pkg/yurtctl/lock" enutil "github.com/alibaba/openyurt/pkg/yurtctl/util/edgenode" kubeutil "github.com/alibaba/openyurt/pkg/yurtctl/util/kubernetes" ) @@ -76,16 +75,6 @@ func (r *RevertEdgeNodeOptions) Complete(flags *pflag.FlagSet) (err error) { } func (r *RevertEdgeNodeOptions) RunRevertEdgeNode() (err error) { - if err = lock.AcquireLock(r.clientSet); err != nil { - return - } - defer func() { - if releaseLockErr := lock.ReleaseLock(r.clientSet); releaseLockErr != nil { - klog.Error(releaseLockErr) - } - }() - klog.V(4).Info("successfully acquire the lock") - // 1. check the server version if err = kubeutil.ValidateServerVersion(r.clientSet); err != nil { return @@ -158,13 +147,13 @@ func (r *RevertEdgeNodeOptions) RevertKubelet() error { if err := cmd.Exec(); err != nil { return err } - fmt.Println(cmd.GetStdOut()) + klog.Info(cmd.GetStdOut()) cmd = enutil.NewCommand(enutil.RestartKubeletSvc) if err := cmd.Exec(); err != nil { return err } - fmt.Println(cmd.GetStdOut()) + klog.Info(cmd.GetStdOut()) klog.Infof("kubelet has been reset back to default") return nil } diff --git a/pkg/yurtctl/cmd/revert/revert.go b/pkg/yurtctl/cmd/revert/revert.go index 40225a928a6..66502102af7 100644 --- a/pkg/yurtctl/cmd/revert/revert.go +++ b/pkg/yurtctl/cmd/revert/revert.go @@ -224,6 +224,7 @@ func (ro *RevertOptions) RunRevert() (err error) { // 7. remove yurt-hub and revert kubelet service if err = kubeutil.RunServantJobs(ro.clientSet, map[string]string{ + "action": "revert", "yurtctl_servant_image": ro.YurtctlServantImage, }, edgeNodeNames, false); err != nil { diff --git a/pkg/yurtctl/constants/constants.go b/pkg/yurtctl/constants/constants.go index 5b10d942dc1..cc60691fb09 100644 --- a/pkg/yurtctl/constants/constants.go +++ b/pkg/yurtctl/constants/constants.go @@ -184,7 +184,7 @@ spec: imagePullPolicy: Always command: - /bin/sh - - -c + - -c args: - "nsenter -t 1 -m -u -n -i /bin/yurtctl convert edgenode --yurthub-image {{.yurthub_image}} --join-token {{.joinToken}} --pod-manifest-path {{.pod_manifest_path}}" securityContext: @@ -224,7 +224,7 @@ spec: imagePullPolicy: Always command: - /bin/sh - - -c + - -c args: - "nsenter -t 1 -m -u -n -i /bin/yurtctl revert edgenode" securityContext: diff --git a/pkg/yurtctl/util/edgenode/common.go b/pkg/yurtctl/util/edgenode/common.go index e1fd1468b5e..dbac784cccc 100644 --- a/pkg/yurtctl/util/edgenode/common.go +++ b/pkg/yurtctl/util/edgenode/common.go @@ -12,8 +12,8 @@ const ( KubeletHostname = "--hostname-override=[^\"\\s]*" KubeletEnvironmentFile = "EnvironmentFile=.*" - DaemonReload = "daemon-reload" - RestartKubeletSvc = "restart kubelet.service" + DaemonReload = "systemctl daemon-reload" + RestartKubeletSvc = "systemctl restart kubelet" ServerHealthzServer = "127.0.0.1:10261" ServerHealthzUrlPath = "/v1/healthz" @@ -21,17 +21,17 @@ const ( apiVersion: v1 clusters: - cluster: -server: http://127.0.0.1:10261 -name: default-cluster + server: http://127.0.0.1:10261 + name: default-cluster contexts: - context: -cluster: default-cluster -namespace: default -user: default-auth -name: default-context + cluster: default-cluster + namespace: default + user: default-auth + name: default-context current-context: default-context kind: Config -preferences: {} +preferences: {} ` YurthubTemplate = ` apiVersion: v1 diff --git a/pkg/yurtctl/util/edgenode/exec.go b/pkg/yurtctl/util/edgenode/exec.go index 20d915c3c00..a4a2b4a75e5 100644 --- a/pkg/yurtctl/util/edgenode/exec.go +++ b/pkg/yurtctl/util/edgenode/exec.go @@ -18,7 +18,7 @@ type Command struct { func NewCommand(command string) *Command { return &Command{ - Cmd: exec.Command("systemctl", command), + Cmd: exec.Command("bash", "-c", command), } } diff --git a/pkg/yurtctl/util/edgenode/util.go b/pkg/yurtctl/util/edgenode/util.go index ffbd70c3014..d2dc8ebec75 100644 --- a/pkg/yurtctl/util/edgenode/util.go +++ b/pkg/yurtctl/util/edgenode/util.go @@ -100,6 +100,6 @@ func GetNodeName() (string, error) { if err != nil { return "", err } - nodeName = string(content) + nodeName = strings.Trim(string(content), "\n") return nodeName, nil }