Skip to content

chore: Implement workspace proxy going away (graceful shutdown) #7459

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
May 11, 2023
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 remote-tracking branch 'origin/main' into stevenmasley/proxy_go…
…ing_away
  • Loading branch information
Emyrk committed May 10, 2023
commit 38eace73c8947d17f1fafa347569dc7381f9a2a5
27 changes: 17 additions & 10 deletions codersdk/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspacePr
if res.StatusCode != http.StatusCreated {
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
}
var resp UpdateWorkspaceProxyResponse
var resp CreateWorkspaceProxyResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
}

Expand All @@ -111,22 +111,29 @@ func (c *Client) WorkspaceProxies(ctx context.Context) ([]WorkspaceProxy, error)
return proxies, json.NewDecoder(res.Body).Decode(&proxies)
}

func (c *Client) WorkspaceProxyByName(ctx context.Context, name string) (WorkspaceProxy, error) {
res, err := c.Request(ctx, http.MethodGet,
fmt.Sprintf("/api/v2/workspaceproxies/%s", name),
nil,
type PatchWorkspaceProxy struct {
ID uuid.UUID `json:"id" format:"uuid" validate:"required"`
Name string `json:"name" validate:"required"`
DisplayName string `json:"display_name" validate:"required"`
Icon string `json:"icon" validate:"required"`
RegenerateToken bool `json:"regenerate_token"`
}

func (c *Client) PatchWorkspaceProxy(ctx context.Context, req PatchWorkspaceProxy) (UpdateWorkspaceProxyResponse, error) {
res, err := c.Request(ctx, http.MethodPatch,
fmt.Sprintf("/api/v2/workspaceproxies/%s", req.ID.String()),
req,
)
if err != nil {
return WorkspaceProxy{}, xerrors.Errorf("make request: %w", err)
return UpdateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return WorkspaceProxy{}, ReadBodyAsError(res)
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
}

var proxy WorkspaceProxy
return proxy, json.NewDecoder(res.Body).Decode(&proxy)
var resp UpdateWorkspaceProxyResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
}

func (c *Client) DeleteWorkspaceProxyByName(ctx context.Context, name string) error {
Expand Down
127 changes: 3 additions & 124 deletions docs/api/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceproxies \
"errors": ["string"],
"warnings": ["string"]
},
"status": "ok"
"status": "reachable"
},
"updated_at": "2019-08-24T14:15:22Z",
"url": "string",
Expand All @@ -1216,7 +1216,6 @@ Status Code **200**
| `[array item]` | array | false | | |
| `» created_at` | string(date-time) | false | | |
| `» deleted` | boolean | false | | |
| `» display_name` | string | false | | |
| `» icon` | string | false | | |
| `» id` | string(uuid) | false | | |
| `» name` | string | false | | |
Expand All @@ -1234,7 +1233,7 @@ Status Code **200**

| Property | Value |
| -------- | -------------- |
| `status` | `ok` |
| `status` | `reachable` |
| `status` | `unreachable` |
| `status` | `unhealthy` |
| `status` | `unregistered` |
Expand Down Expand Up @@ -1279,7 +1278,6 @@ curl -X POST http://coder-server:8080/api/v2/workspaceproxies \
{
"created_at": "2019-08-24T14:15:22Z",
"deleted": true,
"display_name": "string",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
Expand All @@ -1289,7 +1287,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaceproxies \
"errors": ["string"],
"warnings": ["string"]
},
"status": "ok"
"status": "reachable"
},
"updated_at": "2019-08-24T14:15:22Z",
"url": "string",
Expand All @@ -1305,58 +1303,6 @@ curl -X POST http://coder-server:8080/api/v2/workspaceproxies \

To perform this operation, you must be authenticated. [Learn more](authentication.md).

## Get workspace proxy

### Code samples

```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/workspaceproxies/{workspaceproxy} \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```

`GET /workspaceproxies/{workspaceproxy}`

### Parameters

| Name | In | Type | Required | Description |
| ---------------- | ---- | ------------ | -------- | ---------------- |
| `workspaceproxy` | path | string(uuid) | true | Proxy ID or name |

### Example responses

> 200 Response

```json
{
"created_at": "2019-08-24T14:15:22Z",
"deleted": true,
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"status": {
"checked_at": "2019-08-24T14:15:22Z",
"report": {
"errors": ["string"],
"warnings": ["string"]
},
"status": "ok"
},
"updated_at": "2019-08-24T14:15:22Z",
"url": "string",
"wildcard_hostname": "string"
}
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------------------ |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.WorkspaceProxy](schemas.md#codersdkworkspaceproxy) |

To perform this operation, you must be authenticated. [Learn more](authentication.md).

## Delete workspace proxy

### Code samples
Expand Down Expand Up @@ -1400,70 +1346,3 @@ curl -X DELETE http://coder-server:8080/api/v2/workspaceproxies/{workspaceproxy}
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.Response](schemas.md#codersdkresponse) |

To perform this operation, you must be authenticated. [Learn more](authentication.md).

## Update workspace proxy

### Code samples

```shell
# Example request using curl
curl -X PATCH http://coder-server:8080/api/v2/workspaceproxies/{workspaceproxy} \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```

`PATCH /workspaceproxies/{workspaceproxy}`

> Body parameter

```json
{
"display_name": "string",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"regenerate_token": true
}
```

### Parameters

| Name | In | Type | Required | Description |
| ---------------- | ---- | ---------------------------------------------------------------------- | -------- | ------------------------------ |
| `workspaceproxy` | path | string(uuid) | true | Proxy ID or name |
| `body` | body | [codersdk.PatchWorkspaceProxy](schemas.md#codersdkpatchworkspaceproxy) | true | Update workspace proxy request |

### Example responses

> 200 Response

```json
{
"created_at": "2019-08-24T14:15:22Z",
"deleted": true,
"display_name": "string",
"icon": "string",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"status": {
"checked_at": "2019-08-24T14:15:22Z",
"report": {
"errors": ["string"],
"warnings": ["string"]
},
"status": "reachable"
},
"updated_at": "2019-08-24T14:15:22Z",
"url": "string",
"wildcard_hostname": "string"
}
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------------------ |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.WorkspaceProxy](schemas.md#codersdkworkspaceproxy) |

To perform this operation, you must be authenticated. [Learn more](authentication.md).
3 changes: 2 additions & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func New(ctx context.Context, options *Options) (*API, error) {
httpmw.ExtractWorkspaceProxyParam(api.Database),
)

r.Get("/", api.fetchWorkspaceProxy)
r.Get("/", api.workspaceProxy)
r.Patch("/", api.patchWorkspaceProxy)
r.Delete("/", api.deleteWorkspaceProxy)
})
})
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.