Skip to content

Commit fa0df57

Browse files
committed
feat: Add provisionerd service
This brings an async service that parses and provisions to life! It's separated from coderd intentionally to allow for simpler testing. Integration with coderd will come in another PR!
1 parent ac617e1 commit fa0df57

File tree

12 files changed

+1013
-51
lines changed

12 files changed

+1013
-51
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ replace github.com/hashicorp/terraform-config-inspect => github.com/kylecarbs/te
1010

1111
require (
1212
cdr.dev/slog v1.4.1
13+
github.com/coder/retry v1.3.0
1314
github.com/go-chi/chi/v5 v5.0.7
1415
github.com/go-chi/render v1.0.1
1516
github.com/go-playground/validator/v10 v10.10.0
@@ -18,6 +19,7 @@ require (
1819
github.com/hashicorp/go-version v1.4.0
1920
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
2021
github.com/hashicorp/terraform-exec v0.15.0
22+
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87
2123
github.com/justinas/nosurf v1.1.1
2224
github.com/lib/pq v1.10.4
2325
github.com/moby/moby v20.10.12+incompatible

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWH
232232
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
233233
github.com/cockroachdb/cockroach-go/v2 v2.1.1/go.mod h1:7NtUnP6eK+l6k483WSYNrq3Kb23bWV10IRV1TyeSpwM=
234234
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
235+
github.com/coder/retry v1.3.0 h1:5lAAwt/2Cm6lVmnfBY7sOMXcBOwcwJhmV5QGSELIVWY=
236+
github.com/coder/retry v1.3.0/go.mod h1:tXuRgZgWjUnU5LZPT4lJh4ew2elUhexhlnXzrJWdyFY=
235237
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
236238
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
237239
github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
@@ -688,6 +690,8 @@ github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKEN
688690
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
689691
github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY=
690692
github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk=
693+
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 h1:xixZ2bWeofWV68J+x6AzmKuVM/JWCQwkWm6GW/MUR6I=
694+
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
691695
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
692696
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
693697
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

peerbroker/dial_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/pion/webrtc/v3"
88
"github.com/stretchr/testify/require"
99
"go.uber.org/goleak"
10-
"storj.io/drpc/drpcconn"
1110

1211
"cdr.dev/slog"
1312
"cdr.dev/slog/sloggers/slogtest"
@@ -37,7 +36,7 @@ func TestDial(t *testing.T) {
3736
})
3837
require.NoError(t, err)
3938

40-
api := proto.NewDRPCPeerBrokerClient(drpcconn.New(client))
39+
api := proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client))
4140
stream, err := api.NegotiateConnection(ctx)
4241
require.NoError(t, err)
4342
clientConn, err := peerbroker.Dial(stream, []webrtc.ICEServer{{

peerbroker/listen.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"context"
55
"errors"
66
"io"
7+
"net"
78
"reflect"
89
"sync"
910

1011
"github.com/pion/webrtc/v3"
1112
"golang.org/x/xerrors"
12-
"storj.io/drpc"
1313
"storj.io/drpc/drpcmux"
1414
"storj.io/drpc/drpcserver"
1515

@@ -19,7 +19,7 @@ import (
1919

2020
// Listen consumes the transport as the server-side of the PeerBroker dRPC service.
2121
// The Accept function must be serviced, or new connections will hang.
22-
func Listen(transport drpc.Transport, opts *peer.ConnOptions) (*Listener, error) {
22+
func Listen(connListener net.Listener, opts *peer.ConnOptions) (*Listener, error) {
2323
ctx, cancelFunc := context.WithCancel(context.Background())
2424
listener := &Listener{
2525
connectionChannel: make(chan *peer.Conn),
@@ -39,7 +39,7 @@ func Listen(transport drpc.Transport, opts *peer.ConnOptions) (*Listener, error)
3939
}
4040
srv := drpcserver.New(mux)
4141
go func() {
42-
err := srv.ServeOne(ctx, transport)
42+
err := srv.Serve(ctx, connListener)
4343
_ = listener.closeWithError(err)
4444
}()
4545

peerbroker/listen_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77

88
"github.com/stretchr/testify/require"
9-
"storj.io/drpc/drpcconn"
109

1110
"github.com/coder/coder/peerbroker"
1211
"github.com/coder/coder/peerbroker/proto"
@@ -27,7 +26,7 @@ func TestListen(t *testing.T) {
2726
listener, err := peerbroker.Listen(server, nil)
2827
require.NoError(t, err)
2928

30-
api := proto.NewDRPCPeerBrokerClient(drpcconn.New(client))
29+
api := proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client))
3130
stream, err := api.NegotiateConnection(ctx)
3231
require.NoError(t, err)
3332
clientConn, err := peerbroker.Dial(stream, nil, nil)

provisioner/terraform/parse_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111

1212
"github.com/stretchr/testify/require"
13-
"storj.io/drpc/drpcconn"
1413

1514
"github.com/coder/coder/provisionersdk"
1615
"github.com/coder/coder/provisionersdk/proto"
@@ -30,12 +29,12 @@ func TestParse(t *testing.T) {
3029
go func() {
3130
err := Serve(ctx, &ServeOptions{
3231
ServeOptions: &provisionersdk.ServeOptions{
33-
Transport: server,
32+
Listener: server,
3433
},
3534
})
3635
require.NoError(t, err)
3736
}()
38-
api := proto.NewDRPCProvisionerClient(drpcconn.New(client))
37+
api := proto.NewDRPCProvisionerClient(provisionersdk.Conn(client))
3938

4039
for _, testCase := range []struct {
4140
Name string

provisioner/terraform/provision_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111

1212
"github.com/stretchr/testify/require"
13-
"storj.io/drpc/drpcconn"
1413

1514
"github.com/coder/coder/provisionersdk"
1615
"github.com/coder/coder/provisionersdk/proto"
@@ -29,12 +28,12 @@ func TestProvision(t *testing.T) {
2928
go func() {
3029
err := Serve(ctx, &ServeOptions{
3130
ServeOptions: &provisionersdk.ServeOptions{
32-
Transport: server,
31+
Listener: server,
3332
},
3433
})
3534
require.NoError(t, err)
3635
}()
37-
api := proto.NewDRPCProvisionerClient(drpcconn.New(client))
36+
api := proto.NewDRPCProvisionerClient(provisionersdk.Conn(client))
3837

3938
for _, testCase := range []struct {
4039
Name string

0 commit comments

Comments
 (0)