watcher

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package watcher subscribes to filesystem changes and triggers reloads.

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.

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 single Trigger callback. 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, trigger func(reason string)) (*Watcher, error)

New starts an fsnotify watcher on the unique parent directories of the given paths.

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.

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