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

refactor(ipc)!: make it consistent with the structure of ovm-win #44

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions cmd/ovm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {
exit(1)
}

event.Notify(event.Initializing)
event.NotifyApp(event.Initializing)

ctx, cancel := context.WithCancel(context.Background())
g, ctx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -159,7 +159,7 @@ func ready(ctx context.Context, g *errgroup.Group, opt *cli.Context, log *logger
err = rerr
} else {
channel.NotifyVMReady()
event.Notify(event.VMReady)
event.NotifyApp(event.Ready)
}

if cerr := conn.Close(); cerr != nil {
Expand All @@ -174,7 +174,7 @@ func ready(ctx context.Context, g *errgroup.Group, opt *cli.Context, log *logger
}

func exit(exitCode int) {
event.Notify(event.Exit)
event.NotifyApp(event.Exit)
for _, clean := range cleans {
clean()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gvproxy/gvproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Run(ctx context.Context, g *errgroup.Group, opt *cli.Context) error {
httpServe(ctx, g, ln, mux)

channel.NotifyGVProxyReady()
event.Notify(event.GVProxyReady)
event.NotifyApp(event.GVProxyReady)

g.Go(func() error {
select {
Expand Down
37 changes: 22 additions & 15 deletions pkg/ipc/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ import (
"golang.org/x/sync/errgroup"
)

type Name string

var (
Initializing Name = "Initializing"
GVProxyReady Name = "GVProxyReady"
IgnitionProgress Name = "IgnitionProgress"
IgnitionDone Name = "IgnitionDone"
VMReady Name = "VMReady"
Exit Name = "Exit"
Error Name = "Error"
type key string

const (
kApp key = "app"
kError key = "error"
)

type app string

const (
Initializing app = "Initializing"
GVProxyReady app = "GVProxyReady"
IgnitionProgress app = "IgnitionProgress"
IgnitionDone app = "IgnitionDone"
Ready app = "Ready"
Exit app = "Exit"
)

type datum struct {
name Name
name key
message string
}

Expand Down Expand Up @@ -91,7 +97,7 @@ func Subscribe(g *errgroup.Group) {
}
}

if datum.name == Exit {
if datum.message == string(Exit) {
e.channel.Close()
e = nil
return nil
Expand All @@ -102,13 +108,14 @@ func Subscribe(g *errgroup.Group) {
})
}

func Notify(name Name) {
func NotifyApp(name app) {
if e == nil {
return
}

e.channel.In() <- &datum{
name: name,
name: kApp,
message: string(name),
}
}

Expand All @@ -118,7 +125,7 @@ func NotifyError(err error) {
}

e.channel.In() <- &datum{
name: Error,
name: kError,
message: err.Error(),
}
}
2 changes: 1 addition & 1 deletion pkg/vfkit/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ignition(ctx context.Context, g *errgroup.Group, opt *cli.Context, log *log
err = werr
} else {
log.Info("write ignition command success")
event.Notify(event.IgnitionDone)
event.NotifyApp(event.IgnitionDone)
}

if cerr := conn.Close(); cerr != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vfkit/vfkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Run(ctx context.Context, g *errgroup.Group, opt *cli.Context) error {
return err
}

event.Notify(event.IgnitionProgress)
event.NotifyApp(event.IgnitionProgress)

if err := ignition(ctx, g, opt, log); err != nil {
log.Errorf("ignition failed: %v", err)
Expand Down