Merge pull request #1455 from prodanlabs/karmadactl-feature
delete the karmada data directory before installing with init
This commit is contained in:
commit
43748ff38e
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -70,7 +71,7 @@ type CommandInitOption struct {
|
|||
|
||||
// Validate Check that there are enough flags to run the command.
|
||||
func (i *CommandInitOption) Validate(parentCommand string) error {
|
||||
if !utils.PathIsExist(i.KubeConfig) {
|
||||
if !utils.IsExist(i.KubeConfig) {
|
||||
return fmt.Errorf("kubeconfig file does not exist.absolute path to the kubeconfig file")
|
||||
}
|
||||
|
||||
|
@ -129,6 +130,13 @@ func (i *CommandInitOption) Complete() error {
|
|||
}
|
||||
}
|
||||
|
||||
// Determine whether KarmadaDataPath exists, if so, delete it
|
||||
if utils.IsExist(i.KarmadaDataPath) {
|
||||
if err := os.RemoveAll(i.KarmadaDataPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,10 @@ const (
|
|||
labelSeparator = "="
|
||||
)
|
||||
|
||||
// PathIsExist Determine whether the path exists
|
||||
func PathIsExist(path string) bool {
|
||||
// IsExist Determine whether the path exists
|
||||
func IsExist(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(path, 0755); err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// StringToNetIP String To NetIP
|
||||
|
|
Loading…
Reference in New Issue