Skip to content
Closed
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
Fix linting error
  • Loading branch information
kylecarbs committed Mar 4, 2022
commit 74f0328d78437296a11a926d7b296fe45ae6604a
5 changes: 3 additions & 2 deletions cli/workspaceagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"net/url"
"os"

"github.com/coder/coder/agent"
"github.com/coder/coder/codersdk"
"github.com/powersj/whatsthis/pkg/cloud"
"github.com/spf13/cobra"
"golang.org/x/xerrors"

"github.com/coder/coder/agent"
"github.com/coder/coder/codersdk"
)

func workspaceAgent() *cobra.Command {
Expand Down
1 change: 1 addition & 0 deletions cli/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ func workspaces() *cobra.Command {
cmd := &cobra.Command{
Use: "workspaces",
}
cmd.AddCommand(workspaceAgent())
cmd.AddCommand(workspaceCreate())

return cmd
Expand Down
1 change: 0 additions & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func New(options *Options) (http.Handler, func()) {
r.Get("/", api.provisionerJobResourcesByID)
r.Route("/{workspaceresource}", func(r chi.Router) {
r.Use(httpmw.ExtractWorkspaceResourceParam(options.Database))
r.Get("/", api.provisionerJobResourceByID)
r.Get("/agent", api.workspaceAgentConnectByResource)
})
})
Expand Down
42 changes: 2 additions & 40 deletions coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,47 +249,9 @@ func (api *api) provisionerJobResourcesByID(rw http.ResponseWriter, r *http.Requ
return
}
resources, err := api.Database.GetProvisionerJobResourcesByJobID(r.Context(), job.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get provisioner job resources: %s", err),
})
return
}
apiResources := make([]ProvisionerJobResource, 0)
for _, resource := range resources {
if !resource.AgentID.Valid {
apiResources = append(apiResources, convertProvisionerJobResource(resource, nil))
continue
}
agent, err := api.Database.GetProvisionerJobAgentByResourceID(r.Context(), resource.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get provisioner job agent: %s", err),
})
return
}
apiAgent, err := convertProvisionerJobAgent(agent)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("convert provisioner job agent: %s", err),
})
return
}
apiResources = append(apiResources, convertProvisionerJobResource(resource, &apiAgent))
}
render.Status(r, http.StatusOK)
render.JSON(rw, r, apiResources)
}

func (api *api) provisionerJobResourceByID(rw http.ResponseWriter, r *http.Request) {
job := httpmw.ProvisionerJobParam(r)
if !convertProvisionerJob(job).Status.Completed() {
httpapi.Write(rw, http.StatusPreconditionFailed, httpapi.Response{
Message: "Job hasn't completed!",
})
return
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
resources, err := api.Database.GetProvisionerJobResourcesByJobID(r.Context(), job.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get provisioner job resources: %s", err),
Expand Down
5 changes: 3 additions & 2 deletions coderd/workspaceagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"

"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/agent"
Expand All @@ -16,8 +19,6 @@ import (
"github.com/coder/coder/peerbroker"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestWorkspaceAgentServe(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions codersdk/workspaceagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"golang.org/x/xerrors"
"nhooyr.io/websocket"

"github.com/google/uuid"
"github.com/hashicorp/yamux"

"github.com/coder/coder/coderd"
"github.com/coder/coder/httpmw"
"github.com/coder/coder/peer"
"github.com/coder/coder/peerbroker"
"github.com/coder/coder/peerbroker/proto"
"github.com/coder/coder/provisionersdk"
"github.com/google/uuid"
"github.com/hashicorp/yamux"
)

// AuthenticateWorkspaceAgentUsingGoogleCloudIdentity uses the Google Compute Engine Metadata API to
Expand Down
4 changes: 2 additions & 2 deletions database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (q *fakeQuerier) GetProvisionerJobAgentByInstanceID(_ context.Context, inst
return database.ProvisionerJobAgent{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetProvisionerJobAgentByResourceID(ctx context.Context, resourceID uuid.UUID) (database.ProvisionerJobAgent, error) {
func (q *fakeQuerier) GetProvisionerJobAgentByResourceID(_ context.Context, resourceID uuid.UUID) (database.ProvisionerJobAgent, error) {
q.mutex.Lock()
defer q.mutex.Unlock()

Expand Down Expand Up @@ -962,7 +962,7 @@ func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg databas
return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateProvisionerJobAgentByID(ctx context.Context, arg database.UpdateProvisionerJobAgentByIDParams) error {
func (q *fakeQuerier) UpdateProvisionerJobAgentByID(_ context.Context, arg database.UpdateProvisionerJobAgentByIDParams) error {
q.mutex.Lock()
defer q.mutex.Unlock()

Expand Down