Skip to content

Commit

Permalink
Allows force deletion of the cluster.
Browse files Browse the repository at this point in the history
Fixes  #11
  • Loading branch information
Ranjandas committed May 23, 2024
1 parent 8ce8425 commit b1c7b6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ func StartLimaVM(vmName string, wg *sync.WaitGroup, errCh chan<- error) {
fmt.Printf("Lima VM %s started successfully.\n", vmName)
}

func DeleteLimaVM(vmName string, wg *sync.WaitGroup, errCh chan<- error) {
func DeleteLimaVM(vmName string, force bool, wg *sync.WaitGroup, errCh chan<- error) {
defer wg.Done()

// Define the command to spawn a Lima VM
cmd := exec.Command("limactl", "delete", vmName)
cmd := exec.Command("limactl", "delete", "-f", vmName)

if force {
// Force destroy the VMs
cmd = exec.Command("limactl", "delete", "-f", vmName)
}

// Set the output to os.Stdout and os.Stderr
cmd.Stdout = os.Stdout
Expand Down
6 changes: 5 additions & 1 deletion cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var destroyCmd = &cobra.Command{
// Stop Lima VMs concurrently
for _, vmName := range stoppedInstances {
wg.Add(1)
go lima.DeleteLimaVM(vmName.Name, &wg, errCh)
go lima.DeleteLimaVM(vmName.Name, force, &wg, errCh)
// @TODO - Serialize properly
time.Sleep(10 * time.Second)
}
Expand All @@ -58,6 +58,8 @@ var destroyCmd = &cobra.Command{
},
}

var force bool // whether to force delete the vm

func init() {
rootCmd.AddCommand(destroyCmd)

Expand All @@ -70,5 +72,7 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// destroyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

destroyCmd.Flags().StringVarP(&name, "name", "n", "shikari", "name of the cluster")
destroyCmd.Flags().BoolVarP(&force, "force", "f", false, "force destruction of the cluster even when VMs are running")
}

0 comments on commit b1c7b6f

Please sign in to comment.