Skip to content

Commit

Permalink
Fix bugs about karmada-data dir lost
Browse files Browse the repository at this point in the history
Signed-off-by: jwcesign <jiangwei115@huawei.com>
  • Loading branch information
jwcesign committed Sep 21, 2022
1 parent d81f0ff commit 9a1a425
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/karmadactl/cmdinit/kubernetes/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,21 @@ 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 initializeDirectory(i.KarmadaDataPath)
}

// initializeDirectory clean up the directory path if it exists, then recreate it
func initializeDirectory(path string) error {
// Initialize karmada-data directory.
// If the directory already exists, just clean it up.
if utils.IsExist(path) {
if err := os.RemoveAll(path); err != nil {
return err
}
}
if err := os.MkdirAll(path, os.FileMode(0755)); err != nil {
return fmt.Errorf("failed to create directory: %s, error: %v", path, err)
}

return nil
}
Expand Down

0 comments on commit 9a1a425

Please sign in to comment.