Skip to content

Introduce directory watch abstraction#7307

Open
twz123 wants to merge 4 commits intok0sproject:mainfrom
twz123:watchdir
Open

Introduce directory watch abstraction#7307
twz123 wants to merge 4 commits intok0sproject:mainfrom
twz123:watchdir

Conversation

@twz123
Copy link
Copy Markdown
Member

@twz123 twz123 commented Mar 18, 2026

Description

In preparation of #7308:

Encapsulate fsnotify behind a directory-oriented watch API with a custom event model.

Adapt the applier manager to use the new abstraction instead of fsnotify directly. While doing so, keep stack keys relative to the manifests bundle directory, instead of using joined paths.

Add a debouncing directory change watcher on top of the new watch API to group accepted directory watch events into debounced change bursts and invoke a callback after a quiet period. This replaces the previous raw fsnotify plus debouncer pattern, providing a more streamlined approach that can be reused across k0s components.

Use the directory change watcher for watching manifest stacks, containerd drop-ins and OCI image archives. Remove the now-unused debounce package.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

twz123 added 4 commits March 18, 2026 16:28
Encapsulate fsnotify behind a directory-oriented watch API with a custom
event model.

Adapt the applier manager to use the new abstraction instead of fsnotify
directly. While doing so, keep stack keys relative to the manifests
bundle directory, instead of using joined paths.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
Add internal/os/watch.OnDirChange on top of watch.Dir to group accepted
directory watch events into debounced change bursts and invoke a
callback after a quiet period.

This replaces the previous raw fsnotify plus debouncer pattern,
providing a more streamlined approach that can be reused across k0s
components.

Use the new helper in the stack applier.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
Switch containerd drop-in watching from raw fsnotify plus Debouncer to
the new way of doing it.

Add the new RejectActivations predicate the drop-in watcher ignores
the initial watch activation event and only restarts containerd after
subsequent filesystem changes.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
Switch the OCI bundle directory watching from the old debouncer-based
flow to internal/os/watch.OnDirChange. Add the new InitialDelay field to
OnDirChange so that the initial timeout after activation can be shorter.
Remove the now-unused debounce package.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
@twz123 twz123 marked this pull request as ready for review March 18, 2026 18:43
@twz123 twz123 requested review from a team as code owners March 18, 2026 18:43
@twz123 twz123 requested review from kke and makhov March 18, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant