CSI: fix HTTP routing for external volume list

The HTTP router did not correctly route `/v1/volumes/external` without being
explicitly added to the top-level router. Break this out into its own request
handler.
This commit is contained in:
Tim Gross
2021-04-07 10:34:06 -04:00
committed by Tim Gross
parent cd2eea1286
commit ddc73681a3
2 changed files with 6 additions and 19 deletions

View File

@@ -18,23 +18,6 @@ func (s *HTTPServer) CSIVolumesRequest(resp http.ResponseWriter, req *http.Reque
return nil, CodedError(405, ErrInvalidMethod)
}
// Tokenize the suffix of the path to get the volume id
reqSuffix := strings.TrimPrefix(req.URL.Path, "/v1/volumes")
tokens := strings.Split(reqSuffix, "/")
if len(tokens) == 2 {
if tokens[1] == "external" {
return s.csiVolumesListExternal(resp, req)
}
return nil, CodedError(404, resourceNotFoundErr)
} else if len(tokens) > 2 {
return nil, CodedError(404, resourceNotFoundErr)
}
return s.csiVolumesList(resp, req)
}
func (s *HTTPServer) csiVolumesList(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
// Type filters volume lists to a specific type. When support for non-CSI volumes is
// introduced, we'll need to dispatch here
query := req.URL.Query()
@@ -64,7 +47,10 @@ func (s *HTTPServer) csiVolumesList(resp http.ResponseWriter, req *http.Request)
return out.Volumes, nil
}
func (s *HTTPServer) csiVolumesListExternal(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
func (s *HTTPServer) CSIExternalVolumesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != http.MethodGet {
return nil, CodedError(405, ErrInvalidMethod)
}
args := structs.CSIVolumeExternalListRequest{}
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
@@ -80,7 +66,7 @@ func (s *HTTPServer) csiVolumesListExternal(resp http.ResponseWriter, req *http.
}
setMeta(resp, &out.QueryMeta)
return out.Volumes, nil
return out, nil
}
// CSIVolumeSpecificRequest dispatches GET and PUT

View File

@@ -266,6 +266,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
s.mux.HandleFunc("/v1/deployment/", s.wrap(s.DeploymentSpecificRequest))
s.mux.HandleFunc("/v1/volumes", s.wrap(s.CSIVolumesRequest))
s.mux.HandleFunc("/v1/volumes/external", s.wrap(s.CSIExternalVolumesRequest))
s.mux.HandleFunc("/v1/volumes/snapshot", s.wrap(s.CSISnapshotsRequest))
s.mux.HandleFunc("/v1/volume/csi/", s.wrap(s.CSIVolumeSpecificRequest))
s.mux.HandleFunc("/v1/plugins", s.wrap(s.CSIPluginsRequest))