Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic host volumes: basic CLI CRUD #24382

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

tgross
Copy link
Member

@tgross tgross commented Nov 6, 2024

This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549

@tgross tgross added this to the 1.10.0 milestone Nov 6, 2024
@tgross tgross force-pushed the dynamic-host-volumes branch from 1d8323b to dae28c9 Compare November 7, 2024 14:38
@tgross tgross force-pushed the dynamic-host-volumes branch from dae28c9 to 39d63c8 Compare November 7, 2024 19:42
@tgross tgross force-pushed the dynamic-host-volumes branch from 40f6063 to da738e7 Compare November 8, 2024 20:24
@tgross tgross force-pushed the dynamic-host-volumes branch from 7f7f726 to f650d18 Compare November 11, 2024 16:48
@tgross tgross marked this pull request as ready for review November 11, 2024 17:20
@tgross tgross marked this pull request as draft November 11, 2024 17:24
@tgross tgross marked this pull request as ready for review November 11, 2024 17:26
Copy link
Member

@gulducat gulducat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! I have some food for thought, but no blockers

api/host_volumes.go Outdated Show resolved Hide resolved
api/host_volumes.go Outdated Show resolved Hide resolved
Comment on lines +61 to +63
// HostPath is the path on disk where the volume's mount point was
// created. We record this to make debugging easier.
HostPath string `mapstructure:"host_path" hcl:"host_path"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users can't (shouldn't be able to) override this, right? so why hcl tag?

...on second thought, I guess it must be for Register, where the volume will have been created out-of-band.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, only for Register.

Comment on lines +85 to +87
HostVolumeStatePending HostVolumeState = "pending"
HostVolumeStateReady HostVolumeState = "ready"
HostVolumeStateDeleted HostVolumeState = "deleted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a node becomes unavailable, temporary or otherwise? would it go back to pending, or might we want unknown or similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't really cover that feature in the RFC. I think we'll need to figure out whether there's any notion of liveness when we start on the client-side work.

Comment on lines +124 to +128
func parseConstraints(result *[]*api.Constraint, list *ast.ObjectList) error {
for _, o := range list.Elem().Items {
valid := []string{
"attribute",
"distinct_hosts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little surprised this isn't already a thing somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was! We ripped it out with the rest of HCL1 jobspec parsing. Because everything other than jobspecs is still HCL1, I needed to resurrect this from the code we removed.

command/volume_create_host_test.go Outdated Show resolved Hide resolved
command/volume_status.go Outdated Show resolved Hide resolved
if exactMatchesCount == 1 {
return match, nil, nil
}
return nil, vols, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil pointer and nil error still makes me twitchy, and it'd be pretty easy to handle a consistent slice at the call site instead. i.e. I'd prefer the return signature of this method be ([]*api.HostVolumeStub, error)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do that, the caller has to length-check the return value for (0, 1, many), which just repeats the logic we've done here and doesn't improve the ergonomics much.

Think of it not as nil, nil but as (obj, nil), nil or (nil, obj), nil. This return value is the same as what we do in all the other places in the CLI where we do prefix-matching to find a single object. (There's even a generic helper for this getByPrefix[T], but we can't use it here because the query function doesn't quite match the type param there.)

if code != 0 {
return code
switch typeArg {
case "csi", "":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tangentially related display comment:

nomad volume status with no args currently shows

Container Storage Interface
No CSI volumes

the bold heading pushes me towards showing all (both) types of volumes with respective headers, unless a -type flag is provided to request a specific single type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't love how the "bare" version works... I thought I had a TODO here to refactor the whole way we've got volume status split out but I must've dropped it. Will leave a note for myself on that.

command/volume_status_csi.go Outdated Show resolved Hide resolved
tgross added a commit that referenced this pull request Nov 11, 2024
The `volume status :id` command outputs the namespace for a CSI volume
twice. Drop the second output.

Ref: #24382 (comment)
@tgross tgross merged commit 3fc6835 into dynamic-host-volumes Nov 11, 2024
17 checks passed
@tgross tgross deleted the dhv-cli-crud branch November 11, 2024 20:51
tgross added a commit that referenced this pull request Nov 11, 2024
The `volume status :id` command outputs the namespace for a CSI volume
twice. Drop the second output.

Ref: #24382 (comment)
tgross added a commit that referenced this pull request Nov 18, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Nov 20, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Dec 2, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Dec 3, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Dec 9, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Dec 13, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
tgross added a commit that referenced this pull request Dec 19, 2024
This changeset implements a first pass at the CLI for Dynamic Host Volumes.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants