Skip to content

Commit dc5b0e2

Browse files
authored
Merge pull request #70 from AkihiroSuda/dev-refactor
nits
2 parents 2a32137 + e1a382a commit dc5b0e2

File tree

9 files changed

+73
-19
lines changed

9 files changed

+73
-19
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Lima launches Linux virtual machines with automatic file sharing, port forwardin
99
Lima can be considered as a some sort of unofficial "macOS subsystem for Linux", or "containerd for Mac".
1010

1111
Lima is expected to be used on macOS hosts, but can be used on Linux hosts as well.
12-
It may work on NetBSD and Windows hosts as well.
1312

1413
✅ Automatic file sharing
1514

Diff for: cmd/limactl/start.go

+40-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/AkihiroSuda/lima/pkg/start"
1414
"github.com/AkihiroSuda/lima/pkg/store"
1515
"github.com/AkihiroSuda/lima/pkg/store/filenames"
16+
"github.com/AlecAivazis/survey/v2"
1617
"github.com/containerd/containerd/identifiers"
1718
"github.com/mattn/go-isatty"
1819
"github.com/norouter/norouter/cmd/norouter/editorcmd"
@@ -94,14 +95,21 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
9495
}
9596

9697
if clicontext.Bool("tty") {
97-
yBytes, err = openEditor(clicontext, instName, yBytes)
98+
answerOpenEditor, err := askWhetherToOpenEditor(instName)
9899
if err != nil {
99-
return nil, err
100+
logrus.WithError(err).Warn("Failed to open TUI")
101+
answerOpenEditor = false
100102
}
101-
if len(yBytes) == 0 {
102-
logrus.Info("Aborting, as requested by saving the file with empty content")
103-
os.Exit(0)
104-
return nil, errors.New("should not reach here")
103+
if answerOpenEditor {
104+
yBytes, err = openEditor(clicontext, instName, yBytes)
105+
if err != nil {
106+
return nil, err
107+
}
108+
if len(yBytes) == 0 {
109+
logrus.Info("Aborting, as requested by saving the file with empty content")
110+
os.Exit(0)
111+
return nil, errors.New("should not reach here")
112+
}
105113
}
106114
} else {
107115
logrus.Info("Terminal is not available, proceeding without opening an editor")
@@ -129,6 +137,32 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
129137
return store.Inspect(instName)
130138
}
131139

140+
func askWhetherToOpenEditor(name string) (bool, error) {
141+
var ans string
142+
prompt := &survey.Select{
143+
Message: fmt.Sprintf("Creating an instance %q", name),
144+
Options: []string{
145+
"Proceed with the default configuration",
146+
"Open an editor to override the configuration",
147+
"Exit",
148+
},
149+
}
150+
if err := survey.AskOne(prompt, &ans); err != nil {
151+
return false, err
152+
}
153+
switch ans {
154+
case prompt.Options[0]:
155+
return false, nil
156+
case prompt.Options[1]:
157+
return true, nil
158+
case prompt.Options[2]:
159+
os.Exit(0)
160+
return false, errors.New("should not reach here")
161+
default:
162+
return false, errors.Errorf("unexpected answer %q", ans)
163+
}
164+
}
165+
132166
// openEditor opens an editor, and returns the content (not path) of the modified yaml.
133167
//
134168
// openEditor returns nil when the file was saved as an empty file, optionally with whitespaces.

Diff for: cmd/limactl/stop.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ func stopInstanceGracefully(inst *store.Instance) error {
5959
return errors.Errorf("expected status %q, got %q", store.StatusRunning, inst.Status)
6060
}
6161

62+
begin := time.Now() // used for logrus propagation
6263
logrus.Infof("Sending SIGINT to hostagent process %d", inst.HostAgentPID)
6364
if err := syscall.Kill(inst.HostAgentPID, syscall.SIGINT); err != nil {
6465
logrus.Error(err)
6566
}
6667

6768
logrus.Info("Waiting for the host agent and the qemu processes to shut down")
68-
return waitForHostAgentTermination(context.TODO(), inst)
69+
return waitForHostAgentTermination(context.TODO(), inst, begin)
6970
}
7071

71-
func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) error {
72+
func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begin time.Time) error {
7273
ctx2, cancel := context.WithTimeout(ctx, 3*time.Minute)
7374
defer cancel()
7475

@@ -87,7 +88,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) erro
8788
haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
8889
haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
8990

90-
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); err != nil {
91+
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
9192
return err
9293
}
9394

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0
7+
github.com/AlecAivazis/survey/v2 v2.2.12
78
github.com/alessio/shellescape v1.4.1
89
github.com/containerd/containerd v1.5.2
910
github.com/containerd/continuity v0.1.0

Diff for: go.sum

+19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3737
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3838
github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0 h1:3wgWVUj7BBfqekwj8muvFjGsLEo0Qga6FHhKL1yitEY=
3939
github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0/go.mod h1:85HSbV+AEm8Q/sbrx69Q4GQ9MT9OccwnH0ITcOWfO3Q=
40+
github.com/AlecAivazis/survey/v2 v2.2.12 h1:5a07y93zA6SZ09gOa9wLVLznF5zTJMQ+pJ3cZK4IuO8=
41+
github.com/AlecAivazis/survey/v2 v2.2.12/go.mod h1:6d4saEvBsfSHXeN1a5OA5m2+HJ2LuVokllnC77pAIKI=
4042
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
4143
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
4244
github.com/Azure/go-autorest v10.8.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
@@ -76,6 +78,8 @@ github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+V
7678
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
7779
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
7880
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
81+
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
82+
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
7983
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
8084
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
8185
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
@@ -427,6 +431,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
427431
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
428432
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
429433
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
434+
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
435+
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
430436
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
431437
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
432438
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -448,6 +454,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
448454
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
449455
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
450456
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
457+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
458+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
451459
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
452460
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
453461
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -466,6 +474,8 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
466474
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
467475
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
468476
github.com/kr/pty v1.1.4-0.20190131011033-7dc38fb350b1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
477+
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
478+
github.com/kr/pty v1.1.5 h1:hyz3dwM5QLc1Rfoz4FuWJQG5BN7tc6K1MndAUnGpQr4=
469479
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
470480
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
471481
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
@@ -477,14 +487,19 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7
477487
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
478488
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0=
479489
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
490+
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
491+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
480492
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
493+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
481494
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
482495
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
483496
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
484497
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
485498
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
486499
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
487500
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
501+
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
502+
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
488503
github.com/mibk/dupl v1.0.0/go.mod h1:pCr4pNxxIbFGvtyCOi0c7LVjmV6duhKWV+ex5vh38ME=
489504
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
490505
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
@@ -642,6 +657,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
642657
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
643658
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
644659
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
660+
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
645661
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
646662
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
647663
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -716,6 +732,7 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
716732
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
717733
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
718734
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
735+
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
719736
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
720737
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
721738
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -835,13 +852,15 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
835852
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
836853
golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
837854
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
855+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
838856
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
839857
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
840858
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
841859
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
842860
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
843861
golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
844862
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
863+
golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
845864
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
846865
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
847866
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

Diff for: pkg/hostagent/api/eventwatcher.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, onEvent func(Event) bool) error {
14-
begin := time.Now()
13+
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
1514
haStdoutTail, err := tail.TailFile(haStdoutPath,
1615
tail.Config{
1716
Follow: true,

Diff for: pkg/logrusutil/logrusutil.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/sirupsen/logrus"
99
)
1010

11+
const epsilon = 1 * time.Second
12+
1113
// PropagateJSON propagates JSONFormatter lines.
1214
//
1315
// PanicLevel and FatalLevel are converted to ErrorLevel.
@@ -24,7 +26,7 @@ func PropagateJSON(logger *logrus.Logger, jsonLine []byte, header string, begin
2426
if err := json.Unmarshal(jsonLine, &j); err != nil {
2527
goto fallback
2628
}
27-
if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time) {
29+
if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time.Add(epsilon)) {
2830
return
2931
}
3032
lv, err = logrus.ParseLevel(j.Level)

Diff for: pkg/start/start.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func Start(ctx context.Context, inst *store.Instance) error {
8080
haCmd.Stdout = haStdoutW
8181
haCmd.Stderr = haStderrW
8282

83+
begin := time.Now() // used for logrus propagation
84+
8385
if err := haCmd.Start(); err != nil {
8486
return err
8587
}
@@ -88,7 +90,7 @@ func Start(ctx context.Context, inst *store.Instance) error {
8890
return err
8991
}
9092

91-
return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath)
93+
return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath, begin)
9294
// leave the hostagent process running
9395
}
9496

@@ -106,7 +108,7 @@ func waitHostAgentStart(ctx context.Context, haPIDPath, haStderrPath string) err
106108
}
107109
}
108110

109-
func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string) error {
111+
func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string, begin time.Time) error {
110112
ctx2, cancel := context.WithTimeout(ctx, 10*time.Minute)
111113
defer cancel()
112114

@@ -142,7 +144,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
142144
return false
143145
}
144146

145-
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); xerr != nil {
147+
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
146148
return xerr
147149
}
148150

Diff for: pkg/store/store.go

-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ func InstanceDir(name string) (string, error) {
6565

6666
// LoadYAMLByFilePath loads and validates the yaml.
6767
func LoadYAMLByFilePath(filePath string) (*limayaml.LimaYAML, error) {
68-
if _, err := os.Stat(filePath); err != nil {
69-
return nil, err
70-
}
7168
yContent, err := os.ReadFile(filePath)
7269
if err != nil {
7370
return nil, err

0 commit comments

Comments
 (0)