Files
nomad/command/agent/volumes_endpoint.go
Tim Gross 76641c8081 dynamic host volumes: refactor HTTP routes for volumes list dispatch (#24612)
The List Volumes API was originally written for CSI but assumed we'd have future
volume types, dispatched on a query parameter. Dynamic host volumes uses this,
but the resulting code has host volumes concerns comingled in the CSI volumes
endpoint. Refactor this so that we have a top-level `GET /v1/volumes` route that's
shared between CSI and DHV, and have it dispatch to the appropriate handler in
the type-specific endpoints.

Ref: https://github.com/hashicorp/nomad/pull/24479
2024-12-19 09:25:54 -05:00

28 lines
651 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package agent
import (
"net/http"
"github.com/hashicorp/nomad/nomad/structs"
)
// ListVolumesRequest dispatches requests for listing volumes to a specific type.
func (s *HTTPServer) ListVolumesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
query := req.URL.Query()
qtype, ok := query["type"]
if !ok {
return []*structs.CSIVolListStub{}, nil
}
switch qtype[0] {
case "host":
return s.HostVolumesListRequest(resp, req)
case "csi":
return s.CSIVolumesRequest(resp, req)
default:
return nil, CodedError(404, resourceNotFoundErr)
}
}