Skip to content

Commit

Permalink
remove colony directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jarededwards committed Nov 19, 2024
1 parent 60c8cf1 commit bed4544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,30 @@ func getDestroyCommand() *cobra.Command {
ctx := cmd.Context()
log := logger.New(logger.Debug)

homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("error getting user home directory: %w", err)
}

log.Info("creating docker client")
dockerCLI, err := docker.New(log)
if err != nil {
return fmt.Errorf("error creating docker client: %w", err)
}
defer dockerCLI.Close()

pwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("error getting current working directory: %w", err)
}

err = dockerCLI.RemoveColonyK3sContainer(ctx)
if err != nil {
return fmt.Errorf("error: failed to remove colony container %w", err)
}

err = exec.DeleteFile(filepath.Join(pwd, constants.KubeconfigHostPath))
err = exec.DeleteDirectory(filepath.Join(homeDir, constants.ColonyDir))
if err != nil {
return fmt.Errorf("error: failed to delete kubeconfig file %w", err)
}

//! templates directory is not removed
log.Info("colony installation removed successfully")

log.Info("colony installation removed from host")
return nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func CreateDirIfNotExist(dir string) error {
return nil
}

func DeleteFile(location string) error {
if err := os.Remove(location); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("file %q couldn't be deleted: %w", location, err)
func DeleteDirectory(location string) error {
if err := os.RemoveAll(location); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("%q couldn't be deleted: %w", location, err)
}
return nil
}
Expand Down

0 comments on commit bed4544

Please sign in to comment.