Skip to content

feat: in-process provisionerd connection #1568

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 6 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' of github.com:coder/coder into spike/1375_in_proc…
…_provisionerd_comms
  • Loading branch information
spikecurtis committed May 19, 2022
commit 1f1d7f95baef9030f77ac2b3136ed59993c49d6f
6 changes: 2 additions & 4 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func newRouter(options *Options, a *api) chi.Router {
r.Get("/", a.workspacesByOrganization)
r.Route("/{user}", func(r chi.Router) {
r.Use(httpmw.ExtractUserParam(options.Database))
r.Get("/{workspace}", a.workspaceByOwnerAndName)
r.Get("/{workspacename}", a.workspaceByOwnerAndName)
r.Get("/", a.workspacesByOwner)
})
})
Expand Down Expand Up @@ -246,8 +246,6 @@ func newRouter(options *Options, a *api) chi.Router {
r.Route("/password", func(r chi.Router) {
r.Put("/", a.putUserPassword)
})
r.Get("/organizations", a.organizationsByUser)
r.Post("/organizations", a.postOrganizationsByUser)
// These roles apply to the site wide permissions.
r.Put("/roles", a.putUserRoles)
r.Get("/roles", a.userRoles)
Expand Down Expand Up @@ -319,7 +317,7 @@ func newRouter(options *Options, a *api) chi.Router {
r.Route("/autostop", func(r chi.Router) {
r.Put("/", a.putWorkspaceAutostop)
})
r.Get("/watch", api.watchWorkspace)
r.Get("/watch", a.watchWorkspace)
})
})
r.Route("/workspacebuilds/{workspacebuild}", func(r chi.Router) {
Expand Down
6 changes: 3 additions & 3 deletions coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
t.Parallel()

authorizer := &fakeAuthorizer{}
srv, client, coderDaemon := coderdtest.NewMemoryCoderd(t, &coderdtest.Options{
Authorizer: authorizer,
srv, client, _ := coderdtest.NewWithServer(t, &coderdtest.Options{
Authorizer: authorizer,
IncludeProvisionerD: true,
})
admin := coderdtest.CreateFirstUser(t, client)
organization, err := client.Organization(context.Background(), admin.OrganizationID)
require.NoError(t, err, "fetch org")

// Setup some data in the database.
coderdtest.NewProvisionerDaemon(t, coderDaemon)
version := coderdtest.CreateTemplateVersion(t, client, admin.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, admin.OrganizationID, version.ID)
Expand Down
16 changes: 8 additions & 8 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ type Options struct {

// New constructs an in-memory coderd instance and returns
// the connected client.
func NewMemoryCoderd(t *testing.T, options *Options) (*httptest.Server, *codersdk.Client, coderd.CoderD) {
func New(t *testing.T, options *Options) *codersdk.Client {
_, cli, _ := NewWithServer(t, options)
return cli
}

// NewWithServer returns an in-memory coderd instance and
// the HTTP server it started with.
func NewWithServer(t *testing.T, options *Options) (*httptest.Server, *codersdk.Client, coderd.CoderD) {
if options == nil {
options = &Options{}
}
Expand Down Expand Up @@ -166,13 +173,6 @@ func NewMemoryCoderd(t *testing.T, options *Options) (*httptest.Server, *codersd
return srv, codersdk.New(serverURL), coderDaemon
}

// New constructs an in-memory coderd instance and returns
// the connected client.
func New(t *testing.T, options *Options) *codersdk.Client {
_, cli, _ := NewMemoryCoderd(t, options)
return cli
}

// NewProvisionerDaemon launches a provisionerd instance configured to work
// well with coderd testing. It registers the "echo" provisioner for
// quick testing.
Expand Down
2 changes: 1 addition & 1 deletion coderd/coderdtest/coderdtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMain(m *testing.M) {

func TestNew(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
closer := coderdtest.NewProvisionerDaemon(t, coderDaemon)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
Expand Down
2 changes: 1 addition & 1 deletion coderd/gitsshkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGitSSHKey(t *testing.T) {
func TestAgentGitSSHKey(t *testing.T) {
t.Parallel()

_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
daemonCloser := coderdtest.NewProvisionerDaemon(t, coderDaemon)
authToken := uuid.NewString()
Expand Down
8 changes: 4 additions & 4 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestWorkspaceAgent(t *testing.T) {
t.Parallel()
t.Run("Connect", func(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
daemonCloser := coderdtest.NewProvisionerDaemon(t, coderDaemon)
authToken := uuid.NewString()
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestWorkspaceAgent(t *testing.T) {

func TestWorkspaceAgentListen(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
daemonCloser := coderdtest.NewProvisionerDaemon(t, coderDaemon)
authToken := uuid.NewString()
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestWorkspaceAgentListen(t *testing.T) {

func TestWorkspaceAgentTURN(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
daemonCloser := coderdtest.NewProvisionerDaemon(t, coderDaemon)
authToken := uuid.NewString()
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestWorkspaceAgentPTY(t *testing.T) {
// it seems like it could be either.
t.Skip("ConPTY appears to be inconsistent on Windows.")
}
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
daemonCloser := coderdtest.NewProvisionerDaemon(t, coderDaemon)
authToken := uuid.NewString()
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspacebuilds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestWorkspaceBuildResources(t *testing.T) {
t.Parallel()
t.Run("ListRunning", func(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
closeDaemon := coderdtest.NewProvisionerDaemon(t, coderDaemon)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
Expand Down
7 changes: 3 additions & 4 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestPostWorkspaceBuild(t *testing.T) {

t.Run("AlreadyActive", func(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
closeDaemon := coderdtest.NewProvisionerDaemon(t, coderDaemon)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestPostWorkspaceBuild(t *testing.T) {

t.Run("WithState", func(t *testing.T) {
t.Parallel()
_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, nil)
_, client, coderDaemon := coderdtest.NewWithServer(t, nil)
user := coderdtest.CreateFirstUser(t, client)
closeDaemon := coderdtest.NewProvisionerDaemon(t, coderDaemon)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
Expand Down Expand Up @@ -629,9 +629,8 @@ func mustLocation(t *testing.T, location string) *time.Location {

func TestWorkspaceWatcher(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.