[DNM] pkg/cdi: fixes and cleanups - #344
Draft
thaJeztah wants to merge 14 commits into
Draft
Conversation
Contributor
Author
|
Let me just push the branch I had locally for my own sanity; I think I had some work remaining (last commit), but started to loose track of splitting out to small PRs (for easier review). |
Contributor
Author
|
Ah, right; I needed a go bump for some bits; |
thaJeztah
force-pushed
the
cdi_cleans
branch
5 times, most recently
from
August 24, 2026 08:59
542d33f to
f9ff5c5
Compare
2 tasks
thaJeztah
force-pushed
the
cdi_cleans
branch
2 times, most recently
from
August 24, 2026 09:54
146e9b0 to
51cf822
Compare
Add a matrix to run tests against the oldest supported version (as specified in go.mod), as well as current and previous stable Go. Use a custom name for the job so that the names are stable, which helps when configuring GitHub branch policies. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
InjectDevices only needs to hold the lock while refreshing the cache and capturing the current devices map. Release the lock before resolving devices to reduce lock contention while applying the container edits on the passed-in OCI spec. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This is a constructor, working on a freshly created `Cache`, so there should be no concurrency to account for. While updating, also set the default specDirs directly from a clone of `DefaultSpecDirs`, instead of applying through `WithSpecDirs` to avoid the extra indirect. Paths are still cleaned, to account for the `DefaultSpecDirs` being a mutable, package-level variable (but generally not recommended to update). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Rename vars that shadowed imports, and make sure that the returned errors are properly dereferenced. Also append directory errors instead of overwriting existing errors for the same path. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Both slices.Clone and maps.Clone already handles `nil` values, so we can skip our own checks, making the code slightly more straightforward. Also update GetSpecDirErrors to make sure we perform the copy after obtaining a lock. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Stop the existing watcher before applying new cache options and resetting watcher-related errors, so the old watcher cannot observe partially updated configuration. - Clear the watcher after closing so that we don't leave behind a stale, closed watcher. - Combine watcher setup and startup so creating the fsnotify watcher, installing the initial directory watches, and starting the event loop happen as a single operation. - Install the initial watches explicitly instead of routing startup through `watch.update`, and only initialize `watch.tracked` after successfully creating the watcher. - Avoid starting the watch goroutine if creating the watcher failed. - Remove the now-redundant nil check from `watch.watch` and use its `fsw` argument directly. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
All callers of refreshIfRequired, except `Refresh`, only use it to perform an automatic refresh when necessary and ignore refresh errors. `Refresh`, on the other hand, needs to force a refresh in manual mode and return the cached errors regardless of whether a refresh took place. Move the logic to decide between "automatic" or "forced" refresh to the `Refresh` method, and move collecting the cached / refreshed errors to that method. The responsibility of `Cache.refresh` is now reduced to refreshing the data and errors, and it's up to callers to collect errors when needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
`fsnotify.Event.Op` is a bitmask and can contain multiple operations, but the watcher compared it directly against individual operation values. As a result, combined events could bypass operation-specific handling, such as filtering writes and creates by file extension or detecting removal of a watched directory. Mask the operations we are interested in and test the individual bits instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The watcher filtered write and create events by file extension, but rename and remove events for unrelated files would still trigger a refresh of the CDI cache. Apply the same Spec-file filtering to all relevant filesystem events, while still processing events for configured Spec directories themselves. This avoids unnecessary rescans when non-Spec files in watched directories are renamed or removed, without interfering with handling of removed Spec directories. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pkg/cdi: simplify some code with slices, maps packages
Both slices.Clone and maps.Clone already handles
nilvalues, so we canskip our own checks, making the code slightly more straightforward.
Also update GetSpecDirErrors to make sure we perform the copy after
obtaining a lock.
pkg/cdi: clean up watcher lifecycle handling
watcher-related errors, so the old watcher cannot observe partially updated
configuration.
closed watcher.
installing the initial directory watches, and starting the event loop happen
as a single operation.
watch.update, and only initializewatch.trackedafter successfullycreating the watcher.
watch.watchand use itsfswargument directly.
pkg/cdi: simplify refresh logic
All callers of refreshIfRequired, except
Refresh, only use it to performan automatic refresh when necessary and ignore refresh errors.
Refresh,on the other hand, needs to force a refresh in manual mode and return the
cached errors regardless of whether a refresh took place.
Move the logic to decide between "automatic" or "forced" refresh to the
Refreshmethod, and move collecting the cached / refreshed errors tothat method. The responsibility of
Cache.refreshis now reduced torefreshing the data and errors, and it's up to callers to collect errors
when needed.
pkg/cdi: scope variables and move them closer to where used
pkg/cdi: ListClasses: combine loops
pkg/cdi: handle fsnotify operations as a bitmask
fsnotify.Event.Opis a bitmask and can contain multiple operations, but thewatcher compared it directly against individual operation values.
As a result, combined events could bypass operation-specific handling, such as
filtering writes and creates by file extension or detecting removal of a
watched directory.
Mask the operations we are interested in and test the individual bits instead.
pkg/cdi: ignore unrelated filesystem events
The watcher filtered write and create events by file extension, but rename
and remove events for unrelated files would still trigger a refresh of the
CDI cache.
Apply the same Spec-file filtering to all relevant filesystem events, while
still processing events for configured Spec directories themselves.
This avoids unnecessary rescans when non-Spec files in watched directories are
renamed or removed, without interfering with handling of removed Spec
directories.
WIP: cleanup / fix watch