Skip to content

Commit

Permalink
dynamic host volumes: report Sentinel warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Dec 3, 2024
1 parent 34b84ea commit 85cfbc3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
26 changes: 16 additions & 10 deletions api/host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion command/volume_create_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion command/volume_register_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 85cfbc3

Please sign in to comment.