]> go.fuhry.dev Git - runtime.git/commit
fsnotify: robust support for detecting changes to k8s config objects
authorDan Fuhry <dan@fuhry.com>
Thu, 15 May 2025 21:35:08 +0000 (17:35 -0400)
committerDan Fuhry <dan@fuhry.com>
Thu, 15 May 2025 21:42:01 +0000 (17:42 -0400)
commit6bcb83f362ef859ad4c4b28a735cf64b20cca542
tree265ea49a7c2cfea87b3e7532f87245adec3e940c
parent534420be32bb2480da02b8a49eb304083d0a8a39
fsnotify: robust support for detecting changes to k8s config objects

Kubernetes uses a fairly crazy scheme for files mounted from config maps and in-memory CSI drivers:

  /mnt/file     -> ..data/file
  /mnt/..data   -> ..TIME
  /mnt/..TIME/file (real file)

New versions of the config state are published atomically by doing

  symlink(/mnt/..NEWTIME, /mnt/..data_new)
  rename(/mnt/..data_new, /mnt/..data)

To detect changes to the contents of /mnt/file using inotify instead of polling file contents, we need to detect when /mnt/..data is overwritten.

This requires complex symlink detection and resolution for not only the file but any of the directories in its path, and tracking of final absolute path and inode number to detect when the file was swapped with a different one.

This commit adds that support to fsnotify, along with lots of documentation and tests.
22 files changed:
mtls/fsnotify/all_test.go [new file with mode: 0644]
mtls/fsnotify/fsnotify.go
mtls/fsnotify/fsnotify_test.go [new file with mode: 0644]
mtls/fsnotify/resolve_symlink_tests/01/one [new file with mode: 0644]
mtls/fsnotify/resolve_symlink_tests/02/one [new file with mode: 0644]
mtls/fsnotify/resolve_symlink_tests/02/two [new symlink]
mtls/fsnotify/resolve_symlink_tests/03/one [new file with mode: 0644]
mtls/fsnotify/resolve_symlink_tests/03/three [new symlink]
mtls/fsnotify/resolve_symlink_tests/03/two [new symlink]
mtls/fsnotify/resolve_symlink_tests/04/one [new symlink]
mtls/fsnotify/resolve_symlink_tests/04/two [new symlink]
mtls/fsnotify/resolve_symlink_tests/05/one [new symlink]
mtls/fsnotify/resolve_symlink_tests/05/three [new symlink]
mtls/fsnotify/resolve_symlink_tests/05/two [new symlink]
mtls/fsnotify/resolve_symlink_tests/06/one [new symlink]
mtls/fsnotify/resolve_symlink_tests/07/one [new file with mode: 0644]
mtls/fsnotify/resolve_symlink_tests/07/sub/two [new symlink]
mtls/fsnotify/resolve_symlink_tests/08/one [new symlink]
mtls/fsnotify/resolve_symlink_tests/08/sub/two [new file with mode: 0644]
mtls/fsnotify/util.go [new file with mode: 0644]
mtls/fsnotify/util_test.go [new file with mode: 0644]
utils/checkers/contains_key.go [new file with mode: 0644]