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

Worker notification improvements #246

Merged
merged 2 commits into from
Feb 6, 2025
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
2 changes: 2 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ paths:
type: integer
minimum: 0
maximum: 65535
default: 10
required: false
- in: header
name: Connection
Expand Down Expand Up @@ -393,6 +394,7 @@ paths:
type: integer
minimum: 0
maximum: 65535
default: 0
required: false
responses:
'200':
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/api_vms_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func (controller *Controller) ip(ctx *gin.Context) responder.Responder {
if err != nil {
return responder.Code(http.StatusBadRequest)
}
waitDuration := time.Duration(wait) * time.Second
waitContext, waitContextCancel := context.WithTimeout(ctx, waitDuration)
waitContext, waitContextCancel := context.WithTimeout(ctx, time.Duration(wait)*time.Second)
defer waitContextCancel()

// Look-up the VM
Expand Down
11 changes: 4 additions & 7 deletions internal/controller/api_vms_portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (controller *Controller) portForwardVM(ctx *gin.Context) responder.Responde
if err != nil {
return responder.Code(http.StatusBadRequest)
}
waitDuration := time.Duration(wait) * time.Second
waitContext, waitContextCancel := context.WithTimeout(ctx, waitDuration)
waitContext, waitContextCancel := context.WithTimeout(ctx, time.Duration(wait)*time.Second)
defer waitContextCancel()

// Look-up the VM
Expand All @@ -53,15 +52,15 @@ func (controller *Controller) portForwardVM(ctx *gin.Context) responder.Responde
}

// Commence port-forwarding
return controller.portForward(ctx, vm.Worker, vm.UID, uint32(port), waitDuration)
return controller.portForward(ctx, waitContext, vm.Worker, vm.UID, uint32(port))
}

func (controller *Controller) portForward(
ctx *gin.Context,
notifyContext context.Context,
workerName string,
vmUID string,
port uint32,
waitTimeout time.Duration,
) responder.Responder {
// Request and wait for a connection with a worker
rendezvousCtx, rendezvousCtxCancel := context.WithCancel(ctx)
Expand All @@ -73,9 +72,7 @@ func (controller *Controller) portForward(
defer cancel()

// send request to worker to initiate port-forwarding connection back to us
waitContext, waitContextCancel := context.WithTimeout(ctx, waitTimeout)
defer waitContextCancel()
err := controller.workerNotifier.Notify(waitContext, workerName, &rpc.WatchInstruction{
err := controller.workerNotifier.Notify(notifyContext, workerName, &rpc.WatchInstruction{
Action: &rpc.WatchInstruction_PortForwardAction{
PortForwardAction: &rpc.WatchInstruction_PortForward{
Session: session,
Expand Down
6 changes: 4 additions & 2 deletions internal/controller/api_workers_portforward.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"context"
storepkg "github.com/cirruslabs/orchard/internal/controller/store"
"github.com/cirruslabs/orchard/internal/responder"
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
Expand Down Expand Up @@ -32,7 +33,8 @@ func (controller *Controller) portForwardWorker(ctx *gin.Context) responder.Resp
if err != nil {
return responder.Code(http.StatusBadRequest)
}
waitDuration := time.Duration(wait) * time.Second
waitContext, waitContextCancel := context.WithTimeout(ctx, time.Duration(wait)*time.Second)
defer waitContextCancel()

var worker *v1.Worker

Expand All @@ -48,5 +50,5 @@ func (controller *Controller) portForwardWorker(ctx *gin.Context) responder.Resp
}

// Commence port-forwarding
return controller.portForward(ctx, worker.Name, "", uint32(port), waitDuration)
return controller.portForward(ctx, waitContext, worker.Name, "", uint32(port))
}