dynamic host volumes: allow plugins to return an error message (#25341)

Errors from `volume create` or `volume delete` only get logged by the client
agent, which may make it harder for volume authors to debug these tasks if they
are not also the cluster administrator with access to host logs.

Allow plugins to include an optional error message in their response. Because we
can't count on receiving this response (the error could come before the plugin
executes), we parse this message optimistically and include it only if
available.

Ref: https://hashicorp.atlassian.net/browse/NET-12087
This commit is contained in:
Tim Gross
2025-03-11 11:06:57 -04:00
committed by GitHub
parent 33905d3cdc
commit 1ffb7ab3fb
8 changed files with 66 additions and 18 deletions

View File

@@ -177,6 +177,8 @@ type HostVolumeDeleteRequest struct {
ID string
}
type HostVolumeDeleteResponse struct{}
// Create forwards to client agents so a host volume can be created on those
// hosts, and registers the volume with Nomad servers.
func (hv *HostVolumes) Create(req *HostVolumeCreateRequest, opts *WriteOptions) (*HostVolumeCreateResponse, *WriteMeta, error) {
@@ -236,11 +238,12 @@ func (hv *HostVolumes) List(req *HostVolumeListRequest, opts *QueryOptions) ([]*
}
// Delete deletes a host volume
func (hv *HostVolumes) Delete(req *HostVolumeDeleteRequest, opts *WriteOptions) (*WriteMeta, error) {
func (hv *HostVolumes) Delete(req *HostVolumeDeleteRequest, opts *WriteOptions) (*HostVolumeDeleteResponse, *WriteMeta, error) {
var resp *HostVolumeDeleteResponse
path, err := url.JoinPath("/v1/volume/host/", url.PathEscape(req.ID))
if err != nil {
return nil, err
return nil, nil, err
}
wm, err := hv.client.delete(path, nil, nil, opts)
return wm, err
wm, err := hv.client.delete(path, nil, resp, opts)
return resp, wm, err
}