Skip to content

feat: Add external provisioner daemons #4935

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 23 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Move around provisioner daemons schema
  • Loading branch information
kylecarbs committed Nov 9, 2022
commit 3033c58dd633609540aa0ea73925c5ce5ccf10a4
3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE provisioner_daemons DROP COLUMN auth_token;
ALTER TABLE provisioner_daemons DROP COLUMN tags;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE provisioner_daemons ADD COLUMN tags jsonb;

ALTER TABLE template_versions ADD COLUMN provisioner_tags jsonb;
15 changes: 8 additions & 7 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ func New(ctx context.Context, options *Options) (*API, error) {
r.Get("/", api.group)
})
})

r.Route("/organizations/{organization}/provisionerdaemons", func(r chi.Router) {
r.Use(
apiKeyMiddleware,
)
r.Post("/", api.postProvisionerDaemonsByOrganization)
})
r.Route("/provisionerdaemons", func(r chi.Router) {
r.Use(apiKeyMiddleware)
r.Get("/", api.provisionerDaemons)
r.Get("/listen", api.provisionerDaemonsListen)
r.Post("/", api.postProvisionerDaemonsByOrganization)
})
r.Route("/templates/{template}/acl", func(r chi.Router) {
r.Use(
api.templateRBACEnabledMW,
Expand All @@ -100,7 +111,6 @@ func New(ctx context.Context, options *Options) (*API, error) {
r.Get("/", api.templateACL)
r.Patch("/", api.patchTemplateACL)
})

r.Route("/groups/{group}", func(r chi.Router) {
r.Use(
api.templateRBACEnabledMW,
Expand All @@ -111,7 +121,6 @@ func New(ctx context.Context, options *Options) (*API, error) {
r.Patch("/", api.patchGroup)
r.Delete("/", api.deleteGroup)
})

r.Route("/workspace-quota", func(r chi.Router) {
r.Use(apiKeyMiddleware)
r.Route("/{user}", func(r chi.Router) {
Expand Down
30 changes: 0 additions & 30 deletions enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"net/http"

"github.com/google/uuid"
"github.com/hashicorp/yamux"
"golang.org/x/xerrors"
"nhooyr.io/websocket"
Expand Down Expand Up @@ -54,35 +53,6 @@ func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(ctx, rw, http.StatusOK, daemons)
}

func (api *API) postProvisionerDaemon(rw http.ResponseWriter, r *http.Request) {
if !api.Authorize(r, rbac.ActionCreate, rbac.ResourceProvisionerDaemon) {
httpapi.Forbidden(rw)
return
}

var req codersdk.CreateProvisionerDaemonRequest
if !httpapi.Read(r.Context(), rw, r, &req) {
return
}

provisioner, err := api.Database.InsertProvisionerDaemon(r.Context(), database.InsertProvisionerDaemonParams{
ID: uuid.New(),
CreatedAt: database.Now(),
Name: req.Name,
Provisioners: []database.ProvisionerType{database.ProvisionerTypeTerraform},
AuthToken: uuid.NullUUID{Valid: true, UUID: uuid.New()},
})
if err != nil {
httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{
Message: "Error inserting provisioner daemon.",
Detail: err.Error(),
})
return
}

httpapi.Write(r.Context(), rw, http.StatusCreated, convertProvisionerDaemon(provisioner))
}

// Serves the provisioner daemon protobuf API over a WebSocket.
func (api *API) provisionerDaemonsListen(rw http.ResponseWriter, r *http.Request) {
daemon := httpmw.ProvisionerDaemon(r)
Expand Down