summaryrefslogtreecommitdiff
path: root/keadm
diff options
context:
space:
mode:
authorwujunyi <wu65830600@163.com>2023-09-25 15:14:00 +0800
committerwujunyi <wu65830600@163.com>2023-10-27 00:54:03 +0800
commit9d89875d9d116640e43d119ba70de4f3d74d00f2 (patch)
tree025808f9a4ae46e1b9057fab1b6df91c294c2508 /keadm
parentfeat: download exe from gh release (diff)
downloadkubeedge-9d89875d9d116640e43d119ba70de4f3d74d00f2.tar.gz
chore: add some reset logic
Signed-off-by: wujunyi <wu65830600@163.com>
Diffstat (limited to 'keadm')
-rw-r--r--keadm/cmd/keadm/app/cmd/cmd_windows.go2
-rw-r--r--keadm/cmd/keadm/app/cmd/edge/join_windows.go14
-rw-r--r--keadm/cmd/keadm/app/cmd/reset_windows.go21
-rw-r--r--keadm/cmd/keadm/app/cmd/util/common_windows.go9
-rw-r--r--keadm/cmd/keadm/app/cmd/util/exec.go3
-rw-r--r--keadm/cmd/keadm/app/cmd/util/nssm_test.go5
6 files changed, 39 insertions, 15 deletions
diff --git a/keadm/cmd/keadm/app/cmd/cmd_windows.go b/keadm/cmd/keadm/app/cmd/cmd_windows.go
index 2f65c24c9..af22d2c1e 100644
--- a/keadm/cmd/keadm/app/cmd/cmd_windows.go
+++ b/keadm/cmd/keadm/app/cmd/cmd_windows.go
@@ -1,7 +1,7 @@
//go:build windows
/*
-Copyright 2019 The KubeEdge Authors.
+Copyright 2023 The KubeEdge Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/keadm/cmd/keadm/app/cmd/edge/join_windows.go b/keadm/cmd/keadm/app/cmd/edge/join_windows.go
index f0527c187..60bb8bd17 100644
--- a/keadm/cmd/keadm/app/cmd/edge/join_windows.go
+++ b/keadm/cmd/keadm/app/cmd/edge/join_windows.go
@@ -44,7 +44,6 @@ import (
)
func AddJoinOtherFlags(cmd *cobra.Command, joinOptions *common.JoinOptions) {
-
cmd.Flags().StringVar(&joinOptions.KubeEdgeVersion, common.KubeEdgeVersion, joinOptions.KubeEdgeVersion,
"Use this key to download and use the required KubeEdge version")
cmd.Flags().Lookup(common.KubeEdgeVersion).NoOptDefVal = joinOptions.KubeEdgeVersion
@@ -156,7 +155,14 @@ func join(opt *common.JoinOptions, step *common.Step) error {
step.Printf("Check edge bin exist")
// check if the binary download successfully manual
if !util.FileExists(filepath.Join(util.KubeEdgeUsrBinPath, util.KubeEdgeBinaryName+".exe")) {
- return fmt.Errorf("cannot find edgecore binary at %s, you should download it manual from github release and put edgecore.exe under %s", filepath.Join(util.KubeEdgeUsrBinPath, util.KubeEdgeBinaryName+".exe"), util.KubeEdgeUsrBinPath)
+ fmt.Println("Edge binary not found, start download now")
+ v, err := semver.ParseTolerant(opt.KubeEdgeVersion)
+ if err != nil {
+ return fmt.Errorf("parse kubeedge version failed, %v", err)
+ }
+ if err = util.DownloadEdgecoreBin(common.InstallOptions{}, v); err != nil {
+ return err
+ }
}
step.Printf("Register edgecore as windows service")
@@ -218,13 +224,13 @@ func prepareWindowsNssm(step *common.Step) error {
return nil
}
- fmt.Print("[join] Nssm not found, auto install now? [Y/n]: ")
+ fmt.Print("[join] Nssm not found, auto install now? [y/N]: ")
s := bufio.NewScanner(os.Stdin)
s.Scan()
if err := s.Err(); err != nil {
return err
}
- if strings.ToLower(s.Text()) != "y" && strings.ToLower(s.Text()) != "" {
+ if strings.ToLower(s.Text()) != "y" {
return fmt.Errorf("aborted join operation, please install nssm manually and retry")
}
diff --git a/keadm/cmd/keadm/app/cmd/reset_windows.go b/keadm/cmd/keadm/app/cmd/reset_windows.go
index e09d736f0..b4b8acb80 100644
--- a/keadm/cmd/keadm/app/cmd/reset_windows.go
+++ b/keadm/cmd/keadm/app/cmd/reset_windows.go
@@ -1,7 +1,7 @@
//go:build windows
/*
-Copyright 2022 The KubeEdge Authors.
+Copyright 2023 The KubeEdge Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -65,8 +65,8 @@ func NewKubeEdgeReset() *cobra.Command {
os.Exit(0)
}
whoRunning := util.RunningModuleV2(reset)
- if whoRunning == common.NoneRunning {
- fmt.Println("Edgecore service installed by nssm not found in this host, exit")
+ if whoRunning == common.NoneRunning && !reset.Force {
+ fmt.Println("Edgecore service installed by nssm not found in this host, exit. If you want to clean the related files, using flag --force")
os.Exit(0)
}
return nil
@@ -87,7 +87,17 @@ func NewKubeEdgeReset() *cobra.Command {
// 1. kill edgecore process.
// For edgecore, don't delete node from K8S
if err := TearDownKubeEdge(reset.Kubeconfig); err != nil {
- return fmt.Errorf("err when stop and remove edgecore using nssm: %s", err.Error())
+ err = fmt.Errorf("err when stop and remove edgecore using nssm: %s", err.Error())
+ fmt.Print("[reset] No edgecore running now, do you want to clean all the related directories? [y/N]: ")
+ s := bufio.NewScanner(os.Stdin)
+ s.Scan()
+ if err := s.Err(); err != nil {
+ return err
+ }
+ if strings.ToLower(s.Text()) != "y" {
+ return fmt.Errorf("aborted reset operation")
+ }
+ return cleanDirectories()
}
// 2. Remove containers managed by KubeEdge.
@@ -165,6 +175,7 @@ func cleanDirectories() error {
util.KubeEdgeLogPath,
util.KubeEdgeSocketPath,
util.EdgeRootDir,
+ util.KubeEdgeUsrBinPath,
}
for _, dir := range dirToClean {
@@ -181,7 +192,7 @@ func addResetFlags(cmd *cobra.Command, resetOpts *common.ResetOptions) {
//cmd.Flags().StringVar(&resetOpts.Kubeconfig, common.KubeConfig, resetOpts.Kubeconfig,
// "Use this key to set kube-config path, eg: $HOME/.kube/config")
cmd.Flags().BoolVar(&resetOpts.Force, "force", resetOpts.Force,
- "Reset the node without prompting for confirmation")
+ "Reset the node without prompting for confirmation, and continue even if running edgecore not found")
cmd.Flags().StringVar(&resetOpts.Endpoint, common.RemoteRuntimeEndpoint, resetOpts.Endpoint,
"Use this key to set container runtime endpoint")
}
diff --git a/keadm/cmd/keadm/app/cmd/util/common_windows.go b/keadm/cmd/keadm/app/cmd/util/common_windows.go
index 4b6326fae..22308a8df 100644
--- a/keadm/cmd/keadm/app/cmd/util/common_windows.go
+++ b/keadm/cmd/keadm/app/cmd/util/common_windows.go
@@ -1,7 +1,7 @@
//go:build windows
/*
-Copyright 2019 The KubeEdge Authors.
+Copyright 2023 The KubeEdge Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -90,6 +90,10 @@ func RunningModuleV2(opt *types.ResetOptions) types.ModuleRunning {
return types.NoneRunning
}
+func DownloadEdgecoreBin(options types.InstallOptions, version semver.Version) error {
+ return installKubeEdge(options, version)
+}
+
// installKubeEdge downloads the provided version of KubeEdge Edgecore For windows.
// Untar's in the specified location c:/etc/kubeedge/ and then copies
// the binary to excecutables' path (eg: c:/usr/local/bin)
@@ -158,13 +162,14 @@ func installKubeEdge(options types.InstallOptions, version semver.Version) error
}
// decompress the release pkg
- if err = DecompressTarGz(filePath, filepath.Join(options.TarballPath, dirname)); err != nil {
+ if err = DecompressTarGz(filePath, options.TarballPath); err != nil {
return err
}
// check if the edgecore.exe exists
if !FileExists(filepath.Join(options.TarballPath, dirname, "edge", "edgecore.exe")) {
return fmt.Errorf("cannot find edgecore binary at %s", filepath.Join(options.TarballPath, dirname, "edge", "edgecore.exe"))
}
+ os.MkdirAll(KubeEdgeUsrBinPath, os.ModePerm)
// copy the binary to the executable path
if err = CopyFile(filepath.Join(options.TarballPath, dirname, "edge", "edgecore.exe"), filepath.Join(KubeEdgeUsrBinPath, KubeEdgeBinaryName+".exe")); err != nil {
return err
diff --git a/keadm/cmd/keadm/app/cmd/util/exec.go b/keadm/cmd/keadm/app/cmd/util/exec.go
index aa9724a54..bf282b5f3 100644
--- a/keadm/cmd/keadm/app/cmd/util/exec.go
+++ b/keadm/cmd/keadm/app/cmd/util/exec.go
@@ -4,11 +4,12 @@ import (
"bytes"
"errors"
"fmt"
- "golang.org/x/text/encoding/simplifiedchinese"
"os/exec"
"runtime"
"strings"
"syscall"
+
+ "golang.org/x/text/encoding/simplifiedchinese"
)
// Command defines commands to be executed and captures std out and std error
diff --git a/keadm/cmd/keadm/app/cmd/util/nssm_test.go b/keadm/cmd/keadm/app/cmd/util/nssm_test.go
index 036e24873..d2ff7afd5 100644
--- a/keadm/cmd/keadm/app/cmd/util/nssm_test.go
+++ b/keadm/cmd/keadm/app/cmd/util/nssm_test.go
@@ -4,13 +4,14 @@ package util
import (
"fmt"
- "github.com/stretchr/testify/assert"
"testing"
)
func TestInstallNSSM(t *testing.T) {
err := InstallNSSM()
- assert.NoError(t, err)
+ if err != nil {
+ t.Error(err)
+ }
}
func TestIsServiceExist(t *testing.T) {