Skip to content

Commit

Permalink
change limactl start timeout as command args
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <[email protected]>
  • Loading branch information
Abirdcfly committed Mar 29, 2022
1 parent e021ce7 commit b2e6d70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/limactl/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"fmt"
"io"
Expand All @@ -11,6 +12,7 @@ import (
"path"
"path/filepath"
"strings"
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/containerd/containerd/identifiers"
Expand Down Expand Up @@ -55,6 +57,7 @@ $ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/ma
startCommand.Flags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal")
startCommand.Flags().String("name", "", "override the instance name")
startCommand.Flags().Bool("list-templates", false, "list available templates and exit")
startCommand.Flags().Int("timeout", 600, "start timeout in seconds")
return startCommand
}

Expand Down Expand Up @@ -458,7 +461,14 @@ func startAction(cmd *cobra.Command, args []string) error {
default:
logrus.Warnf("expected status %q, got %q", store.StatusStopped, inst.Status)
}
// fixme: wait cobra 1.5.0 public with https://github.com/spf13/cobra/pull/1551 then use cmd.SetContext(context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second))
ctx := cmd.Context()
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
return err
}
ctx, concel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second)
defer concel()
err = networks.Reconcile(ctx, inst.Name)
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ func waitHostAgentStart(ctx context.Context, haPIDPath, haStderrPath string) err
}

func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPath, haStderrPath string, begin time.Time) error {
ctx2, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()

var (
printedSSHLocalPort bool
Expand Down Expand Up @@ -221,7 +219,7 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
return false
}

if xerr := hostagentevents.Watch(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
if xerr := hostagentevents.Watch(ctx, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
return xerr
}

Expand Down

0 comments on commit b2e6d70

Please sign in to comment.