From 85cfbc32765e0118b86b11adab5eeef0499bf078 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 3 Dec 2024 09:17:15 -0500 Subject: [PATCH] dynamic host volumes: report Sentinel warnings --- api/host_volumes.go | 26 ++++++++++++++++---------- command/volume_create_host.go | 9 ++++++++- command/volume_register_host.go | 10 +++++++++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/api/host_volumes.go b/api/host_volumes.go index 3db16b6b33d..e417177d29c 100644 --- a/api/host_volumes.go +++ b/api/host_volumes.go @@ -160,6 +160,16 @@ type HostVolumeRegisterRequest struct { PolicyOverride bool } +type HostVolumeCreateResponse struct { + Volume *HostVolume + Warnings string +} + +type HostVolumeRegisterResponse struct { + Volume *HostVolume + Warnings string +} + type HostVolumeListRequest struct { NodeID string NodePool string @@ -171,28 +181,24 @@ type HostVolumeDeleteRequest 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) (*HostVolume, *WriteMeta, error) { - var out struct { - Volume *HostVolume - } +func (hv *HostVolumes) Create(req *HostVolumeCreateRequest, opts *WriteOptions) (*HostVolumeCreateResponse, *WriteMeta, error) { + var out *HostVolumeCreateResponse wm, err := hv.client.put("/v1/volume/host/create", req, &out, opts) if err != nil { return nil, wm, err } - return out.Volume, wm, nil + return out, wm, nil } // Register registers a host volume that was created out-of-band with the Nomad // servers. -func (hv *HostVolumes) Register(req *HostVolumeRegisterRequest, opts *WriteOptions) (*HostVolume, *WriteMeta, error) { - var out struct { - Volume *HostVolume - } +func (hv *HostVolumes) Register(req *HostVolumeRegisterRequest, opts *WriteOptions) (*HostVolumeRegisterResponse, *WriteMeta, error) { + var out *HostVolumeRegisterResponse wm, err := hv.client.put("/v1/volume/host/register", req, &out, opts) if err != nil { return nil, wm, err } - return out.Volume, wm, nil + return out, wm, nil } // Get queries for a single host volume, by ID diff --git a/command/volume_create_host.go b/command/volume_create_host.go index 49b407b20dd..dc0d1e1aef2 100644 --- a/command/volume_create_host.go +++ b/command/volume_create_host.go @@ -31,11 +31,18 @@ func (c *VolumeCreateCommand) hostVolumeCreate( Volume: vol, PolicyOverride: override, } - vol, _, err = client.HostVolumes().Create(req, nil) + resp, _, err := client.HostVolumes().Create(req, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error creating volume: %s", err)) return 1 } + vol = resp.Volume + + if resp.Warnings != "" { + c.Ui.Output( + c.Colorize().Color( + fmt.Sprintf("[bold][yellow]Volume Warnings:\n%s[reset]\n", resp.Warnings))) + } var volID string var lastIndex uint64 diff --git a/command/volume_register_host.go b/command/volume_register_host.go index e73febf2b2b..b6cb213caac 100644 --- a/command/volume_register_host.go +++ b/command/volume_register_host.go @@ -21,11 +21,19 @@ func (c *VolumeRegisterCommand) hostVolumeRegister(client *api.Client, ast *ast. Volume: vol, PolicyOverride: override, } - vol, _, err = client.HostVolumes().Register(req, nil) + resp, _, err := client.HostVolumes().Register(req, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error registering volume: %s", err)) return 1 } + vol = resp.Volume + + if resp.Warnings != "" { + c.Ui.Output( + c.Colorize().Color( + fmt.Sprintf("[bold][yellow]Volume Warnings:\n%s[reset]\n", resp.Warnings))) + } + c.Ui.Output(fmt.Sprintf( "Registered host volume %s with ID %s", vol.Name, vol.ID))