Skip to content

fix(enterprise/coderd): check provisionerd API version on connection #12191

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

Merged
merged 8 commits into from
Feb 16, 2024
Prev Previous commit
Next Next commit
restore original signature of codersdk.ServeProvisionerDaemon
  • Loading branch information
johnstcn committed Feb 16, 2024
commit a0afb65ec5470362507052c66b65f68d40c34258
2 changes: 1 addition & 1 deletion coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func NewExternalProvisionerDaemon(t testing.TB, client *codersdk.Client, org uui
}()

daemon := provisionerd.New(func(ctx context.Context) (provisionerdproto.DRPCProvisionerDaemonClient, error) {
return client.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
return client.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: t.Name(),
Organization: org,
Expand Down
9 changes: 4 additions & 5 deletions codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"golang.org/x/xerrors"
"nhooyr.io/websocket"

"github.com/coder/coder/v2/apiversion"
"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/coder/v2/provisionerd/proto"
"github.com/coder/coder/v2/provisionerd/runner"
"github.com/coder/coder/v2/provisionersdk"
)

type LogSource string
Expand Down Expand Up @@ -194,17 +194,16 @@ type ServeProvisionerDaemonRequest struct {
// ServeProvisionerDaemon returns the gRPC service for a provisioner daemon
// implementation. The context is during dial, not during the lifetime of the
// client. Client should be closed after use.
func (c *Client) ServeProvisionerDaemon(ctx context.Context, v *apiversion.APIVersion, req ServeProvisionerDaemonRequest) (proto.DRPCProvisionerDaemonClient, error) {
func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisionerDaemonRequest) (proto.DRPCProvisionerDaemonClient, error) {
serverURL, err := c.URL.Parse(fmt.Sprintf("/api/v2/organizations/%s/provisionerdaemons/serve", req.Organization))
if err != nil {
return nil, xerrors.Errorf("parse url: %w", err)
}
query := serverURL.Query()
query.Add("id", req.ID.String())
query.Add("name", req.Name)
if v != nil { // This is only done in tests
query.Add("version", v.String())
}
query.Add("version", provisionersdk.VersionCurrent.String())

for _, provisioner := range req.Provisioners {
query.Add("provisioner", string(provisioner))
}
Expand Down
2 changes: 1 addition & 1 deletion enterprise/cli/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
}
id := uuid.New()
srv := provisionerd.New(func(ctx context.Context) (provisionerdproto.DRPCProvisionerDaemonClient, error) {
return client.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
return client.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: id,
Name: name,
Provisioners: []codersdk.ProvisionerType{
Expand Down
18 changes: 9 additions & 9 deletions enterprise/coderd/provisionerdaemons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
daemonName := testutil.MustRandString(t, 63)
srv, err := templateAdminClient.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
srv, err := templateAdminClient.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: daemonName,
Organization: user.OrganizationID,
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
daemonName := testutil.MustRandString(t, 63)
_, err := templateAdminClient.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := templateAdminClient.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: daemonName,
Organization: user.OrganizationID,
Expand All @@ -200,7 +200,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
another, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleOrgAdmin(user.OrganizationID))
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
_, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 63),
Organization: user.OrganizationID,
Expand All @@ -227,7 +227,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
another, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
_, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 63),
Organization: user.OrganizationID,
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
defer cancel()
another := codersdk.New(client.URL)
daemonName := testutil.MustRandString(t, 63)
srv, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
srv, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
Name: daemonName,
Organization: user.OrganizationID,
Provisioners: []codersdk.ProvisionerType{
Expand Down Expand Up @@ -387,7 +387,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
}
another := codersdk.New(client.URL)
pd := provisionerd.New(func(ctx context.Context) (provisionerdproto.DRPCProvisionerDaemonClient, error) {
return another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
return another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 63),
Organization: user.OrganizationID,
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
another := codersdk.New(client.URL)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
_, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 32),
Organization: user.OrganizationID,
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
another := codersdk.New(client.URL)
_, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 63),
Organization: user.OrganizationID,
Expand Down Expand Up @@ -533,7 +533,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
another := codersdk.New(client.URL)
_, err := another.ServeProvisionerDaemon(ctx, provisionersdk.VersionCurrent, codersdk.ServeProvisionerDaemonRequest{
_, err := another.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
ID: uuid.New(),
Name: testutil.MustRandString(t, 63),
Organization: user.OrganizationID,
Expand Down