Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete kubefirst file when doing kubefirst reset - KRA-73 #2344

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading