Skip to content

Commit 2f35776

Browse files
committed
pkg/hostagent/api -> pkg/hostagent/events
Signed-off-by: Akihiro Suda <[email protected]>
1 parent bab1029 commit 2f35776

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

cmd/limactl/stop.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"syscall"
1111
"time"
1212

13-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
14-
"github.com/lima-vm/lima/pkg/networks/reconcile"
13+
hostagentevents "github.com/lima-vm/lima/pkg/hostagent/events"
14+
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
1515
"github.com/lima-vm/lima/pkg/store"
1616
"github.com/lima-vm/lima/pkg/store/filenames"
1717
"github.com/sirupsen/logrus"
@@ -78,7 +78,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
7878
defer cancel()
7979

8080
var receivedExitingEvent bool
81-
onEvent := func(ev hostagentapi.Event) bool {
81+
onEvent := func(ev hostagentevents.Event) bool {
8282
if len(ev.Status.Errors) > 0 {
8383
logrus.Errorf("%+v", ev.Status.Errors)
8484
}
@@ -92,7 +92,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
9292
haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
9393
haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
9494

95-
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
95+
if err := hostagentevents.Watch(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
9696
return err
9797
}
9898

docs/internal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Guest agent:
5050

5151
Host agent:
5252
- `ha.pid`: hostagent PID
53-
- `ha.stdout.log`: hostagent stdout (JSON lines, see `pkg/hostagent/api.Events`)
53+
- `ha.stdout.log`: hostagent stdout (JSON lines, see `pkg/hostagent/events.Event`)
5454
- `ha.stderr.log`: hostagent stderr (human-readable messages)
5555

5656
## Lima cache directory (`~/Library/Caches/lima`)

pkg/hostagent/api/api.go renamed to pkg/hostagent/events/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package api
1+
package events
22

33
import (
44
"time"

pkg/hostagent/api/eventwatcher.go renamed to pkg/hostagent/events/watcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package api
1+
package events
22

33
import (
44
"context"
@@ -10,7 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
13+
func Watch(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
1414
haStdoutTail, err := tail.TailFile(haStdoutPath,
1515
tail.Config{
1616
Follow: true,

pkg/hostagent/hostagent.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/hashicorp/go-multierror"
2020
guestagentapi "github.com/lima-vm/lima/pkg/guestagent/api"
2121
guestagentclient "github.com/lima-vm/lima/pkg/guestagent/api/client"
22-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
22+
"github.com/lima-vm/lima/pkg/hostagent/events"
2323
"github.com/lima-vm/lima/pkg/limayaml"
2424
"github.com/lima-vm/lima/pkg/qemu"
2525
"github.com/lima-vm/lima/pkg/sshutil"
@@ -114,7 +114,7 @@ func New(instName string, stdout, stderr io.Writer, sigintCh chan os.Signal) (*H
114114
return a, nil
115115
}
116116

117-
func (a *HostAgent) emitEvent(ctx context.Context, ev hostagentapi.Event) {
117+
func (a *HostAgent) emitEvent(ctx context.Context, ev events.Event) {
118118
a.eventEncMu.Lock()
119119
defer a.eventEncMu.Unlock()
120120
if ev.Time.IsZero() {
@@ -135,8 +135,8 @@ func logPipeRoutine(l *logrus.Logger, r io.Reader, header string) {
135135

136136
func (a *HostAgent) Run(ctx context.Context) error {
137137
defer func() {
138-
exitingEv := hostagentapi.Event{
139-
Status: hostagentapi.Status{
138+
exitingEv := events.Event{
139+
Status: events.Status{
140140
Exiting: true,
141141
},
142142
}
@@ -177,11 +177,11 @@ func (a *HostAgent) Run(ctx context.Context) error {
177177
if sshLocalPort < 0 {
178178
return fmt.Errorf("invalid ssh local port %d", sshLocalPort)
179179
}
180-
stBase := hostagentapi.Status{
180+
stBase := events.Status{
181181
SSHLocalPort: sshLocalPort,
182182
}
183183
stBooting := stBase
184-
a.emitEvent(ctx, hostagentapi.Event{Status: stBooting})
184+
a.emitEvent(ctx, events.Event{Status: stBooting})
185185

186186
go func() {
187187
stRunning := stBase
@@ -190,7 +190,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
190190
stRunning.Errors = append(stRunning.Errors, haErr.Error())
191191
}
192192
stRunning.Running = true
193-
a.emitEvent(ctx, hostagentapi.Event{Status: stRunning})
193+
a.emitEvent(ctx, events.Event{Status: stRunning})
194194
}()
195195

196196
for {

pkg/start/start.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/lima-vm/lima/pkg/cidata"
13-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
13+
hostagentevents "github.com/lima-vm/lima/pkg/hostagent/events"
1414
"github.com/lima-vm/lima/pkg/limayaml"
1515
"github.com/lima-vm/lima/pkg/qemu"
1616
"github.com/lima-vm/lima/pkg/store"
@@ -134,7 +134,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
134134
receivedRunningEvent bool
135135
err error
136136
)
137-
onEvent := func(ev hostagentapi.Event) bool {
137+
onEvent := func(ev hostagentevents.Event) bool {
138138
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
139139
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
140140
printedSSHLocalPort = true
@@ -161,7 +161,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
161161
return false
162162
}
163163

164-
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
164+
if xerr := hostagentevents.Watch(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
165165
return xerr
166166
}
167167

0 commit comments

Comments
 (0)