Introduce "orchard {port-forward, vnc} worker WORKER_NAME" (#140)

* Fix potential NPE in Client.wsRequest()

* Introduce "orchard {port-forward, vnc} worker WORKER_NAME"

* portspec.go: simplify logic and respect [LOCAL_PORT]:REMOTE_PORT format
This commit is contained in:
Nikolay Edigaryev
2023-10-09 18:51:34 +04:00
committed by GitHub
parent 063405672f
commit 13b4e192f0
16 changed files with 408 additions and 92 deletions
+3 -3
View File
@@ -271,10 +271,10 @@ func (client *Client) wsRequest(
if err != nil {
if resp != nil {
_ = resp.Body.Close()
}
if resp.StatusCode == http.StatusNotFound {
err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err)
if resp.StatusCode == http.StatusNotFound {
err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err)
}
}
return nil, err
+13
View File
@@ -4,8 +4,10 @@ import (
"context"
"fmt"
"github.com/cirruslabs/orchard/pkg/resource/v1"
"net"
"net/http"
"net/url"
"strconv"
)
type WorkersService struct {
@@ -65,3 +67,14 @@ func (service *WorkersService) Delete(ctx context.Context, name string) error {
return nil
}
func (service *WorkersService) PortForward(
ctx context.Context,
name string,
port uint16,
) (net.Conn, error) {
return service.client.wsRequest(ctx, fmt.Sprintf("workers/%s/port-forward", url.PathEscape(name)),
map[string]string{
"port": strconv.FormatUint(uint64(port), 10),
})
}