Merge pull request #1455 from prodanlabs/karmadactl-feature

delete the karmada data directory before installing with init
This commit is contained in:
karmada-bot 2022-03-11 15:49:24 +08:00 committed by GitHub
commit 43748ff38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -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
}

View File

@ -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