Skip to content

Commit

Permalink
fix: delete kubefirst file when doing kubefirst reset - KRA-73 (#2344)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: nathan-nicholson <[email protected]>
  • Loading branch information
nathan-nicholson authored Dec 11, 2024
1 parent b7b1e99 commit ca34ec7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ var resetCmd = &cobra.Command{
return fmt.Errorf("unable to determine contents of kubefirst-checks: unexpected type %T", v)
}

if err := runReset(); err != nil {
homePath, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("unable to get user home directory: %w", err)
}

if err := runReset(homePath); err != nil {
return fmt.Errorf("error during reset operation: %w", err)
}
return nil
Expand Down Expand Up @@ -94,19 +99,16 @@ func parseConfigEntryKubefirstChecks(checks map[string]interface{}) (map[string]
}

// runReset carries out the reset function
func runReset() error {
func runReset(homePath string) error {
utils.DisplayLogHints()

progressPrinter.AddTracker("removing-platform-content", "Removing local platform content", 2)
progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false)

log.Info().Msg("removing previous platform content")

homePath, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("unable to get user home directory: %w", err)
}
k1Dir := fmt.Sprintf("%s/.k1", homePath)
kubefirstConfig := fmt.Sprintf("%s/.kubefirst", homePath)

if err := utils.ResetK1Dir(k1Dir); err != nil {
return fmt.Errorf("error resetting k1 directory: %w", err)
Expand All @@ -131,9 +133,12 @@ func runReset() error {
return fmt.Errorf("unable to delete %q folder, error: %w", k1Dir, err)
}

if err := os.RemoveAll(kubefirstConfig); err != nil {
return fmt.Errorf("unable to remove %q, error: %w", kubefirstConfig, err)
}

progressPrinter.IncrementTracker("removing-platform-content")
time.Sleep(time.Second * 2)
progress.Progress.Quit()

return nil
}

0 comments on commit ca34ec7

Please sign in to comment.