mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
csi: change the API paths to match CLI command layout (#7325)
* command/agent/csi_endpoint: support type filter in volumes & plugins * command/agent/http: use /v1/volume/csi & /v1/plugin/csi * api/csi: use /v1/volume/csi & /v1/plugin/csi * api/nodes: use /v1/volume/csi & /v1/plugin/csi * api/nodes: not /volumes/csi, just /volumes * command/agent/csi_endpoint: fix ot parameter parsing
This commit is contained in:
@@ -7,18 +7,30 @@ import (
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
const errRequiresType = "Missing required parameter type"
|
||||
|
||||
func (s *HTTPServer) CSIVolumesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
if req.Method != "GET" {
|
||||
return nil, CodedError(405, ErrInvalidMethod)
|
||||
}
|
||||
|
||||
// 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()
|
||||
qtype, ok := query["type"]
|
||||
if !ok {
|
||||
return nil, CodedError(400, errRequiresType)
|
||||
}
|
||||
if qtype[0] != "csi" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
args := structs.CSIVolumeListRequest{}
|
||||
|
||||
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
query := req.URL.Query()
|
||||
if plugin, ok := query["plugin_id"]; ok {
|
||||
args.PluginID = plugin[0]
|
||||
}
|
||||
@@ -38,7 +50,7 @@ func (s *HTTPServer) CSIVolumesRequest(resp http.ResponseWriter, req *http.Reque
|
||||
// CSIVolumeSpecificRequest dispatches GET and PUT
|
||||
func (s *HTTPServer) CSIVolumeSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// Tokenize the suffix of the path to get the volume id
|
||||
reqSuffix := strings.TrimPrefix(req.URL.Path, "/v1/csi/volume/")
|
||||
reqSuffix := strings.TrimPrefix(req.URL.Path, "/v1/volume/csi/")
|
||||
tokens := strings.Split(reqSuffix, "/")
|
||||
if len(tokens) > 2 || len(tokens) < 1 {
|
||||
return nil, CodedError(404, resourceNotFoundErr)
|
||||
@@ -129,6 +141,17 @@ func (s *HTTPServer) CSIPluginsRequest(resp http.ResponseWriter, req *http.Reque
|
||||
return nil, CodedError(405, ErrInvalidMethod)
|
||||
}
|
||||
|
||||
// Type filters plugin lists to a specific type. When support for non-CSI plugins is
|
||||
// introduced, we'll need to dispatch here
|
||||
query := req.URL.Query()
|
||||
qtype, ok := query["type"]
|
||||
if !ok {
|
||||
return nil, CodedError(400, errRequiresType)
|
||||
}
|
||||
if qtype[0] != "csi" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
args := structs.CSIPluginListRequest{}
|
||||
|
||||
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
||||
@@ -151,7 +174,7 @@ func (s *HTTPServer) CSIPluginSpecificRequest(resp http.ResponseWriter, req *htt
|
||||
}
|
||||
|
||||
// Tokenize the suffix of the path to get the plugin id
|
||||
reqSuffix := strings.TrimPrefix(req.URL.Path, "/v1/csi/plugin/")
|
||||
reqSuffix := strings.TrimPrefix(req.URL.Path, "/v1/plugin/csi/")
|
||||
tokens := strings.Split(reqSuffix, "/")
|
||||
if len(tokens) > 2 || len(tokens) < 1 {
|
||||
return nil, CodedError(404, resourceNotFoundErr)
|
||||
|
||||
@@ -253,10 +253,10 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
|
||||
s.mux.HandleFunc("/v1/deployments", s.wrap(s.DeploymentsRequest))
|
||||
s.mux.HandleFunc("/v1/deployment/", s.wrap(s.DeploymentSpecificRequest))
|
||||
|
||||
s.mux.HandleFunc("/v1/csi/volumes", s.wrap(s.CSIVolumesRequest))
|
||||
s.mux.HandleFunc("/v1/csi/volume/", s.wrap(s.CSIVolumeSpecificRequest))
|
||||
s.mux.HandleFunc("/v1/csi/plugins", s.wrap(s.CSIPluginsRequest))
|
||||
s.mux.HandleFunc("/v1/csi/plugin/", s.wrap(s.CSIPluginSpecificRequest))
|
||||
s.mux.HandleFunc("/v1/volumes", s.wrap(s.CSIVolumesRequest))
|
||||
s.mux.HandleFunc("/v1/volume/csi/", s.wrap(s.CSIVolumeSpecificRequest))
|
||||
s.mux.HandleFunc("/v1/plugins", s.wrap(s.CSIPluginsRequest))
|
||||
s.mux.HandleFunc("/v1/plugin/csi/", s.wrap(s.CSIPluginSpecificRequest))
|
||||
|
||||
s.mux.HandleFunc("/v1/acl/policies", s.wrap(s.ACLPoliciesRequest))
|
||||
s.mux.HandleFunc("/v1/acl/policy/", s.wrap(s.ACLPolicySpecificRequest))
|
||||
|
||||
Reference in New Issue
Block a user