mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
CSI: deletes with API don't have request body
Our API client `delete` method doesn't include a request body, but accepts an interface for the response. We were accidentally putting the request body into the response, which doesn't get picked up in unit tests because we're not reading the (always empty) response body anyways.
This commit is contained in:
14
api/csi.go
14
api/csi.go
@@ -126,10 +126,13 @@ func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISna
|
||||
|
||||
// DeleteSnapshot deletes an external storage volume snapshot.
|
||||
func (v *CSIVolumes) DeleteSnapshot(snap *CSISnapshot, w *WriteOptions) error {
|
||||
req := &CSISnapshotDeleteRequest{
|
||||
Snapshots: []*CSISnapshot{snap},
|
||||
qp := url.Values{}
|
||||
qp.Set("snapshot_id", snap.ID)
|
||||
qp.Set("plugin_id", snap.PluginID)
|
||||
for k, v := range snap.Secrets {
|
||||
qp.Set("secret", fmt.Sprintf("%v=%v", k, v))
|
||||
}
|
||||
_, err := v.client.delete("/v1/volumes/snapshot", req, w)
|
||||
_, err := v.client.delete("/v1/volumes/snapshot?"+qp.Encode(), nil, w)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -397,11 +400,6 @@ type CSISnapshotCreateResponse struct {
|
||||
QueryMeta
|
||||
}
|
||||
|
||||
type CSISnapshotDeleteRequest struct {
|
||||
Snapshots []*CSISnapshot
|
||||
WriteRequest
|
||||
}
|
||||
|
||||
// CSISnapshotListRequest is a request to a controller plugin to list all the
|
||||
// snapshot known to the the storage provider. This request is paginated by
|
||||
// the plugin and accepts the QueryOptions.PerPage and QueryOptions.NextToken
|
||||
|
||||
@@ -298,11 +298,23 @@ func (s *HTTPServer) csiSnapshotCreate(resp http.ResponseWriter, req *http.Reque
|
||||
func (s *HTTPServer) csiSnapshotDelete(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
|
||||
args := structs.CSISnapshotDeleteRequest{}
|
||||
if err := decodeBody(req, &args); err != nil {
|
||||
return err, CodedError(400, err.Error())
|
||||
}
|
||||
s.parseWriteRequest(req, &args.WriteRequest)
|
||||
|
||||
snap := &structs.CSISnapshot{Secrets: structs.CSISecrets{}}
|
||||
|
||||
query := req.URL.Query()
|
||||
snap.PluginID = query.Get("plugin_id")
|
||||
snap.ID = query.Get("snapshot_id")
|
||||
secrets := query["secret"]
|
||||
for _, raw := range secrets {
|
||||
secret := strings.Split(raw, "=")
|
||||
if len(secret) == 2 {
|
||||
snap.Secrets[secret[0]] = secret[1]
|
||||
}
|
||||
}
|
||||
|
||||
args.Snapshots = []*structs.CSISnapshot{snap}
|
||||
|
||||
var out structs.CSISnapshotDeleteResponse
|
||||
if err := s.agent.RPC("CSIVolume.DeleteSnapshot", &args, &out); err != nil {
|
||||
return nil, err
|
||||
|
||||
14
vendor/github.com/hashicorp/nomad/api/csi.go
generated
vendored
14
vendor/github.com/hashicorp/nomad/api/csi.go
generated
vendored
@@ -126,10 +126,13 @@ func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISna
|
||||
|
||||
// DeleteSnapshot deletes an external storage volume snapshot.
|
||||
func (v *CSIVolumes) DeleteSnapshot(snap *CSISnapshot, w *WriteOptions) error {
|
||||
req := &CSISnapshotDeleteRequest{
|
||||
Snapshots: []*CSISnapshot{snap},
|
||||
qp := url.Values{}
|
||||
qp.Set("snapshot_id", snap.ID)
|
||||
qp.Set("plugin_id", snap.PluginID)
|
||||
for k, v := range snap.Secrets {
|
||||
qp.Set("secret", fmt.Sprintf("%v=%v", k, v))
|
||||
}
|
||||
_, err := v.client.delete("/v1/volumes/snapshot", req, w)
|
||||
_, err := v.client.delete("/v1/volumes/snapshot?"+qp.Encode(), nil, w)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -397,11 +400,6 @@ type CSISnapshotCreateResponse struct {
|
||||
QueryMeta
|
||||
}
|
||||
|
||||
type CSISnapshotDeleteRequest struct {
|
||||
Snapshots []*CSISnapshot
|
||||
WriteRequest
|
||||
}
|
||||
|
||||
// CSISnapshotListRequest is a request to a controller plugin to list all the
|
||||
// snapshot known to the the storage provider. This request is paginated by
|
||||
// the plugin and accepts the QueryOptions.PerPage and QueryOptions.NextToken
|
||||
|
||||
Reference in New Issue
Block a user