mirror of
https://github.com/labring/sealos.git
synced 2026-10-24 11:53:32 +08:00
'增加交互clean确认'
This commit is contained in:
+6
-1
@@ -17,6 +17,7 @@ package cmd
|
||||
import (
|
||||
"github.com/fanux/sealos/install"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
// cleanCmd represents the clean command
|
||||
@@ -25,6 +26,10 @@ var cleanCmd = &cobra.Command{
|
||||
Short: "Simplest way to clean your kubernets HA cluster",
|
||||
Long: `sealos clean`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !install.CleanForce { // flase
|
||||
result := install.Confirm(`clean command will clean all masters and nodes, continue clean (y/n)?`)
|
||||
if !result { os.Exit(0) }
|
||||
}
|
||||
deleteNodes := install.ParseIPs(install.NodeIPs)
|
||||
deleteMasters := install.ParseIPs(install.MasterIPs)
|
||||
c := &install.SealConfig{}
|
||||
@@ -40,7 +45,7 @@ func init() {
|
||||
// Here you will define your flags and configuration settings.
|
||||
cleanCmd.Flags().StringSliceVar(&install.NodeIPs, "node", []string{}, "clean node ips.kubernetes multi-nodes ex. 192.168.0.5-192.168.0.5")
|
||||
cleanCmd.Flags().StringSliceVar(&install.MasterIPs, "master", []string{}, "clean master ips.kubernetes multi-nodes ex. 192.168.0.5-192.168.0.5")
|
||||
|
||||
cleanCmd.PersistentFlags().BoolVarP(&install.CleanForce, "force","f", false, "A help for foo")
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// cleanCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
@@ -42,7 +42,7 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZ
|
||||
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fanux/sealgate v0.0.4 h1:vfAQIGIzfQfvcG0qfkPcgXG9xeXu6Z6Bv2d7WjUwh3k=
|
||||
github.com/fanux/sealgate v0.0.4 h1:mvn4j3hNIdravxL3/eeyuO/z/F2BQDjbTFM3Winx0OQ=
|
||||
github.com/fanux/sealgate v0.0.4/go.mod h1:y3141RLsCSgid4+H0O+7CoAqIHDGB0r0mcR8TYnqvps=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/wonderivan/logger"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
)
|
||||
|
||||
//BuildClean is
|
||||
|
||||
+28
-2
@@ -3,6 +3,7 @@ package install
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cuisongliu/sshcmd/pkg/filesize"
|
||||
"github.com/wonderivan/logger"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -13,8 +14,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/wonderivan/logger"
|
||||
)
|
||||
|
||||
const oneMBByte = 1024 * 1024
|
||||
@@ -238,6 +237,33 @@ func ParseIPs(ips []string) []string {
|
||||
return hosts
|
||||
}
|
||||
|
||||
// like y|yes|Y|YES return true
|
||||
func GetConfirmResult(str string) bool {
|
||||
return YesRx.MatchString(str)
|
||||
}
|
||||
|
||||
// send the prompt and get result
|
||||
func Confirm(prompt string) bool {
|
||||
var (
|
||||
inputStr string
|
||||
err error
|
||||
)
|
||||
_, err = fmt.Fprint(os.Stdout, prompt)
|
||||
if err != nil {
|
||||
logger.Error("fmt.Fprint err", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
_, err = fmt.Scanf("%s", inputStr)
|
||||
if err != nil {
|
||||
logger.Error("fmt.Scanf err", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return GetConfirmResult(inputStr)
|
||||
}
|
||||
|
||||
|
||||
func SliceRemoveStr(ss []string, s string) (result []string) {
|
||||
for _, v := range ss {
|
||||
if v != s {
|
||||
|
||||
+8
-1
@@ -1,6 +1,9 @@
|
||||
package install
|
||||
|
||||
import "github.com/cuisongliu/sshcmd/pkg/sshutil"
|
||||
import (
|
||||
"github.com/cuisongliu/sshcmd/pkg/sshutil"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
MasterIPs []string
|
||||
@@ -21,4 +24,8 @@ var (
|
||||
WithoutCNI bool
|
||||
//network interface name, like "eth.*|en.*"
|
||||
Interface string
|
||||
|
||||
YesRx = regexp.MustCompile("^(?i:y(?:es)?)$")
|
||||
|
||||
CleanForce bool
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user