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

event stream: add events for dynamic host volumes #24721

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

tgross
Copy link
Member

@tgross tgross commented Dec 19, 2024

Add a new topic to the event stream for host volumes. We'll emit events when a dynamic host volume is registered or deregistered, and whenever a node fingerprints with a changed volume.

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

CSI will be done in a separate PR.

Testing & Reproduction steps

In addition to the unit tests, you can use nomad operator api "/v1/event/stream?topic=HostVolume" to poll for host volume events while running the host volume demo setup script

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad website documentation to reflect this. Refer to
    the website README for docs guidelines. Please also consider whether the
    change requires notes within the upgrade guide.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.

Add a new topic to the event stream for host volumes. We'll emit events when a
dynamic host volume is registered or deregistered, and whenever a node
fingerprints with a changed volume.

Ref: https://hashicorp.atlassian.net/browse/NET-11549
@tgross tgross changed the title event stream: add events for CSI volumes and dynamic host volumes event stream: add events for dynamic host volumes Dec 19, 2024
@tgross tgross marked this pull request as ready for review December 19, 2024 19:03
@tgross tgross requested review from a team as code owners December 19, 2024 19:03
@tgross tgross requested review from pbortnick, pkazmierczak and gulducat and removed request for pbortnick December 19, 2024 19:03
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.

I have a little flight of fancy to consider, but lgtm!

Comment on lines +386 to +389
return structs.Event{
Topic: structs.TopicHostVolume,
Key: after.ID,
FilterKeys: []string{
Copy link
Member

Choose a reason for hiding this comment

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

DRY bikeshed: what if structs.HostVolume had an Event() method that returned this of itself? then it could be used in both places.

// nomad/structs/host_volumes.go
func (hv *HostVolume) Event() Event {
	if hv == nil {
		return Event{}
	}
	return Event{
		Topic:     TopicHostVolume,
		Key:       hv.ID,
		Namespace: hv.Namespace,
		FilterKeys: []string{
			hv.ID,
			hv.Name,
			hv.PluginID,
		},
		Payload: &HostVolumeEvent{
			Volume: hv,
		},
	}
}

extra bonus bikeshed: if all the other types did this too, then this eventFromChange method could be real small, akin to

type eventer interface {
	Event() structs.Event
}
if thing, ok := change.After.(eventer); ok {
	return thing.Event(), true
} else {
	return structs.Event{}, false
}

so adding something to the event stream could be (almost) as simple as satisfying that interface.

Copy link
Member Author

@tgross tgross Dec 19, 2024

Choose a reason for hiding this comment

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

I was thinking something along those lines while implementing this (and #24724). It'd improve the type safety too. But seeing as how I've already tried to shrink this PR by pulling out the CSI work to its own PR, any such refactoring should probably also be its own PR.

There's also a minor annoyance here too that the Eventer interface must be exported from nomad/structs, but none of that code will be covered by nomad/structs tests. The "test coverage goons" will frown, but there's really no logic there.

@tgross tgross merged commit 9cf0ad9 into main Dec 19, 2024
32 checks passed
@tgross tgross deleted the dhv-event-stream branch December 19, 2024 19:55
gulducat pushed a commit that referenced this pull request Dec 20, 2024
Add a new topic to the event stream for host volumes. We'll emit events when a
dynamic host volume is registered or deregistered, and whenever a node
fingerprints with a changed volume.

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