feat(agent): add container list handler (#16346)

Fixes https://github.com/coder/coder/issues/16268

- Adds `/api/v2/workspaceagents/:id/containers` coderd endpoint that allows listing containers
visible to the agent. Optional filtering by labels is supported.
- Adds go tools to the `coder-dylib` CI step so we can generate mocks if needed
This commit is contained in:
Cian Johnston
2025-02-10 11:29:30 +00:00
committed by GitHub
parent 7076c4e4ab
commit 31b1ff7d3b
22 changed files with 1654 additions and 2 deletions
+65
View File
@@ -638,6 +638,71 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent}/con
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Get running containers for workspace agent
### Code samples
```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent}/containers?label=string \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
`GET /workspaceagents/{workspaceagent}/containers`
### Parameters
| Name | In | Type | Required | Description |
|------------------|-------|-------------------|----------|--------------------|
| `workspaceagent` | path | string(uuid) | true | Workspace agent ID |
| `label` | query | string(key=value) | true | Labels |
### Example responses
> 200 Response
```json
{
"containers": [
{
"created_at": "2019-08-24T14:15:22Z",
"id": "string",
"image": "string",
"labels": {
"property1": "string",
"property2": "string"
},
"name": "string",
"ports": [
{
"network": "string",
"port": 0,
"process_name": "string"
}
],
"running": true,
"status": "string",
"volumes": {
"property1": "string",
"property2": "string"
}
}
],
"warnings": [
"string"
]
}
```
### Responses
| Status | Meaning | Description | Schema |
|--------|---------------------------------------------------------|-------------|----------------------------------------------------------------------------------------------------------|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.WorkspaceAgentListContainersResponse](schemas.md#codersdkworkspaceagentlistcontainersresponse) |
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Coordinate workspace agent
### Code samples
+86
View File
@@ -7561,6 +7561,50 @@ If the schedule is empty, the user will be updated to use the default schedule.|
| `updated_at` | string | false | | |
| `version` | string | false | | |
## codersdk.WorkspaceAgentDevcontainer
```json
{
"created_at": "2019-08-24T14:15:22Z",
"id": "string",
"image": "string",
"labels": {
"property1": "string",
"property2": "string"
},
"name": "string",
"ports": [
{
"network": "string",
"port": 0,
"process_name": "string"
}
],
"running": true,
"status": "string",
"volumes": {
"property1": "string",
"property2": "string"
}
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|--------------------|---------------------------------------------------------------------------------------|----------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `created_at` | string | false | | Created at is the time the container was created. |
| `id` | string | false | | ID is the unique identifier of the container. |
| `image` | string | false | | Image is the name of the container image. |
| `labels` | object | false | | Labels is a map of key-value pairs of container labels. |
| » `[any property]` | string | false | | |
| `name` | string | false | | Name is the human-readable name of the container. |
| `ports` | array of [codersdk.WorkspaceAgentListeningPort](#codersdkworkspaceagentlisteningport) | false | | Ports includes ports exposed by the container. |
| `running` | boolean | false | | Running is true if the container is currently running. |
| `status` | string | false | | Status is the current status of the container. This is somewhat implementation-dependent, but should generally be a human-readable string. |
| `volumes` | object | false | | Volumes is a map of "things" mounted into the container. Again, this is somewhat implementation-dependent. |
| » `[any property]` | string | false | | |
## codersdk.WorkspaceAgentHealth
```json
@@ -7599,6 +7643,48 @@ If the schedule is empty, the user will be updated to use the default schedule.|
| `shutdown_error` |
| `off` |
## codersdk.WorkspaceAgentListContainersResponse
```json
{
"containers": [
{
"created_at": "2019-08-24T14:15:22Z",
"id": "string",
"image": "string",
"labels": {
"property1": "string",
"property2": "string"
},
"name": "string",
"ports": [
{
"network": "string",
"port": 0,
"process_name": "string"
}
],
"running": true,
"status": "string",
"volumes": {
"property1": "string",
"property2": "string"
}
}
],
"warnings": [
"string"
]
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|--------------|-------------------------------------------------------------------------------------|----------|--------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `containers` | array of [codersdk.WorkspaceAgentDevcontainer](#codersdkworkspaceagentdevcontainer) | false | | Containers is a list of containers visible to the workspace agent. |
| `warnings` | array of string | false | | Warnings is a list of warnings that may have occurred during the process of listing containers. This should not include fatal errors. |
## codersdk.WorkspaceAgentListeningPort
```json