Skip to content

Commit

Permalink
modify the yurtctl_servant_image & delete edgenode lock operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Peeknut committed Jan 27, 2021
1 parent e2f5e52 commit 73f8e34
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 53 deletions.
2 changes: 1 addition & 1 deletion config/yurtctl-servant/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM alpine:3.8
FROM ubuntu:20.04
10 changes: 4 additions & 6 deletions hack/lib/release-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -118,22 +118,20 @@ 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
exit 1
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
1 change: 1 addition & 0 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 8 additions & 20 deletions pkg/yurtctl/cmd/convert/edgenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ 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"
)

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
15 changes: 2 additions & 13 deletions pkg/yurtctl/cmd/revert/edgenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtctl/cmd/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurtctl/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions pkg/yurtctl/util/edgenode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ 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"
OpenyurtKubeletConf = `
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
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/util/edgenode/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/util/edgenode/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 73f8e34

Please sign in to comment.