From 6a5fe39c80e4efde2ffee3a56b21eb7f1d04c458 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 7 Apr 2021 08:44:12 -0400 Subject: [PATCH] CSI: fix decoding error on snapshot create Consumers of the CSI HTTP API are expecting a response object and not a slice of snapshots. Fix the return value. --- api/csi.go | 4 ++-- command/agent/csi_endpoint.go | 2 +- command/volume_snapshot_create.go | 2 +- vendor/github.com/hashicorp/nomad/api/csi.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/csi.go b/api/csi.go index c9b0ea744..fd7c6679c 100644 --- a/api/csi.go +++ b/api/csi.go @@ -115,13 +115,13 @@ func (v *CSIVolumes) Detach(volID, nodeID string, w *WriteOptions) error { } // CreateSnapshot snapshots an external storage volume. -func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) ([]*CSISnapshot, *WriteMeta, error) { +func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISnapshotCreateResponse, *WriteMeta, error) { req := &CSISnapshotCreateRequest{ Snapshots: []*CSISnapshot{snap}, } resp := &CSISnapshotCreateResponse{} meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w) - return resp.Snapshots, meta, err + return resp, meta, err } // DeleteSnapshot deletes an external storage volume snapshot. diff --git a/command/agent/csi_endpoint.go b/command/agent/csi_endpoint.go index c352a825e..658d53f59 100644 --- a/command/agent/csi_endpoint.go +++ b/command/agent/csi_endpoint.go @@ -292,7 +292,7 @@ func (s *HTTPServer) csiSnapshotCreate(resp http.ResponseWriter, req *http.Reque } setMeta(resp, &out.QueryMeta) - return out.Snapshots, nil + return out, nil } func (s *HTTPServer) csiSnapshotDelete(resp http.ResponseWriter, req *http.Request) (interface{}, error) { diff --git a/command/volume_snapshot_create.go b/command/volume_snapshot_create.go index 3499c91c0..4fcfdcd73 100644 --- a/command/volume_snapshot_create.go +++ b/command/volume_snapshot_create.go @@ -106,6 +106,6 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int { return 1 } - c.Ui.Output(csiFormatSnapshots(snaps, verbose)) + c.Ui.Output(csiFormatSnapshots(snaps.Snapshots, verbose)) return 0 } diff --git a/vendor/github.com/hashicorp/nomad/api/csi.go b/vendor/github.com/hashicorp/nomad/api/csi.go index c9b0ea744..fd7c6679c 100644 --- a/vendor/github.com/hashicorp/nomad/api/csi.go +++ b/vendor/github.com/hashicorp/nomad/api/csi.go @@ -115,13 +115,13 @@ func (v *CSIVolumes) Detach(volID, nodeID string, w *WriteOptions) error { } // CreateSnapshot snapshots an external storage volume. -func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) ([]*CSISnapshot, *WriteMeta, error) { +func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISnapshotCreateResponse, *WriteMeta, error) { req := &CSISnapshotCreateRequest{ Snapshots: []*CSISnapshot{snap}, } resp := &CSISnapshotCreateResponse{} meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w) - return resp.Snapshots, meta, err + return resp, meta, err } // DeleteSnapshot deletes an external storage volume snapshot.