watcher

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package watcher subscribes to filesystem changes and feeds them into a coalescer.

Why parent-directory watching? Kubernetes ConfigMap mounts use a `..data` symlink that is atomically swapped on update. Watching the target file directly loses events because the inode changes; watching the parent directory and reacting to CREATE / CHMOD on the symlink path is the recommended pattern. The Watcher detects the canonical K8s "..data" rename and tags it as a swap-commit so the coalescer can drain the burst on the SwapHint window instead of the full Quiet window.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher fans fsnotify events out to a Coalescer keyed by parent directory. It survives best-effort recovery: when a watched directory is deleted (e.g. a pod's volume re-mount), the Watcher attempts to re-Add it on the next event.

func New

func New(paths []string, co *coalesce.Coalescer) (*Watcher, error)

New starts an fsnotify watcher on the unique parent directories of the given paths and routes every event through co.

func (*Watcher) AddPath

func (w *Watcher) AddPath(path string) error

AddPath registers a path. If path is an existing directory, the directory itself is watched (non-recursively). Otherwise, the parent directory is watched — the K8s ConfigMap pattern, since the inode of the leaf file changes during atomic swap. Idempotent.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the watcher. Idempotent. The caller is responsible for stopping the associated Coalescer separately.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context)

Run loops until ctx is canceled or Close is called. It is intended to be invoked in its own goroutine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL