MCPcopy Index your code
hub / github.com/coder/coder / workspaceAgentListContainers

Method workspaceAgentListContainers

coderd/workspaceagents.go:909–996  ·  view source on GitHub ↗

@Summary Get running containers for workspace agent @ID get-running-containers-for-workspace-agent @Security CoderSessionToken @Produce json @Tags Agents @Param workspaceagent path string true "Workspace agent ID" format(uuid) @Param label query string true "Labels" format(key=value) @Success 200 {o

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

907// @Success 200 {object} codersdk.WorkspaceAgentListContainersResponse
908// @Router /api/v2/workspaceagents/{workspaceagent}/containers [get]
909func (api *API) workspaceAgentListContainers(rw http.ResponseWriter, r *http.Request) {
910 ctx := r.Context()
911 waws := httpmw.WorkspaceAgentAndWorkspaceParam(r)
912
913 labelParam, ok := r.URL.Query()["label"]
914 if !ok {
915 labelParam = []string{}
916 }
917 labels := make(map[string]string, len(labelParam)/2)
918 for _, label := range labelParam {
919 kvs := strings.Split(label, "=")
920 if len(kvs) != 2 {
921 httpapi.Write(r.Context(), rw, http.StatusBadRequest, codersdk.Response{
922 Message: "Invalid label format",
923 Detail: "Labels must be in the format key=value",
924 })
925 return
926 }
927 labels[kvs[0]] = kvs[1]
928 }
929
930 // If the agent is unreachable, the request will hang. Assume that if we
931 // don't get a response after 30s that the agent is unreachable.
932 ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
933 defer cancel()
934 apiAgent, err := db2sdk.WorkspaceAgent(
935 api.DERPMap(),
936 *api.TailnetCoordinator.Load(),
937 waws.WorkspaceAgent,
938 nil,
939 nil,
940 nil,
941 api.AgentInactiveDisconnectTimeout,
942 api.DeploymentValues.AgentFallbackTroubleshootingURL.String(),
943 )
944 if err != nil {
945 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
946 Message: "Internal error reading workspace agent.",
947 Detail: err.Error(),
948 })
949 return
950 }
951 if apiAgent.Status != codersdk.WorkspaceAgentConnected {
952 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
953 Message: fmt.Sprintf("Agent state is %q, it must be in the %q state.", apiAgent.Status, codersdk.WorkspaceAgentConnected),
954 })
955 return
956 }
957
958 agentConn, release, err := api.agentProvider.AgentConn(ctx, waws.WorkspaceAgent.ID)
959 if err != nil {
960 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
961 Message: "Internal error dialing workspace agent.",
962 Detail: err.Error(),
963 })
964 return
965 }
966 defer release()

Callers

nothing calls this directly

Calls 13

DERPMapMethod · 0.95
WriteFunction · 0.92
WorkspaceAgentFunction · 0.92
AsErrorFunction · 0.92
ContextMethod · 0.65
AgentConnMethod · 0.65
ListContainersMethod · 0.65
LoadMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected