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 to use directional error channels #2617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
return a.startRoutinesAndWait(ctx, errCh)
}

func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh chan error) error {
func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh <-chan error) error {
stBase := events.Status{
SSHLocalPort: a.sshLocalPort,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/wsl2/vm_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func stopVM(ctx context.Context, distroName string) error {
var limaBoot string

// provisionVM starts Lima's boot process inside an already imported VM.
func provisionVM(ctx context.Context, instanceDir, instanceName, distroName string, errCh *chan error) error {
func provisionVM(ctx context.Context, instanceDir, instanceName, distroName string, errCh chan<- error) error {
ciDataPath := filepath.Join(instanceDir, filenames.CIDataISODir)
m := map[string]string{
"CIDataPath": ciDataPath,
Expand Down Expand Up @@ -120,7 +120,7 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
os.RemoveAll(limaBootFileWinPath)
logrus.Debugf("%v: %q", cmd.Args, string(out))
if err != nil {
*errCh <- fmt.Errorf(
errCh <- fmt.Errorf(
"error running wslCommand that executes boot.sh (%v): %w, "+
"check /var/log/lima-init.log for more details (out=%q)", cmd.Args, err, string(out))
}
Expand All @@ -139,7 +139,7 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
}

// keepAlive runs a background process which in order to keep the WSL2 VM running in the background after launch.
func keepAlive(ctx context.Context, distroName string, errCh *chan error) {
func keepAlive(ctx context.Context, distroName string, errCh chan<- error) {
keepAliveCmd := exec.CommandContext(
ctx,
"wsl.exe",
Expand All @@ -152,7 +152,7 @@ func keepAlive(ctx context.Context, distroName string, errCh *chan error) {

go func() {
if err := keepAliveCmd.Run(); err != nil {
*errCh <- fmt.Errorf(
errCh <- fmt.Errorf(
"error running wsl keepAlive command: %w", err)
}
}()
Expand Down
4 changes: 2 additions & 2 deletions pkg/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
l.BaseDriver.Instance.Dir,
l.BaseDriver.Instance.Name,
distroName,
&errCh,
errCh,
); err != nil {
return nil, err
}

keepAlive(ctx, distroName, &errCh)
keepAlive(ctx, distroName, errCh)

return errCh, err
}
Expand Down
Loading