Skip to content

Avoid restarting the Tilt hub for unchanged kind kubeconfigs - #1056

Merged
cwilhit merged 2 commits into
mainfrom
codex/preview-kubeconfig-noop
Nov 12, 2026
Merged

cwilhit merged 2 commits into
mainfrom
codex/preview-kubeconfig-noop

Conversation

@railgrid-factory

@railgrid-factory railgrid-factory Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Repeated kind bootstrap calls change kubeconfig metadata even when its contents and permissions already match. Tilt observes the chmod event and restarts the embedded hub while provider registration is running, producing transient OpenAPI and connection failures.

Skip chmod when the file is already private. Keep atomic replacement for changed contents and permission repair, including special mode bits.

e2e-infrastructure-up now refreshes an existing cluster's kubeconfig with the same writer instead of kind get kubeconfig > …, so that file is also written atomically, kept at 0600 and left alone when unchanged. A new writer test checks on every platform, including macOS, that an unchanged refresh keeps the inode, ctime and mtime; the inotify test stays Linux-only.

Validation: make test-dev-browser (6 writer tests, 20 browser setup tests); a real owned-kind no-op refresh emitted zero filesystem events and preserved inode, mtime and ctime. After the follow-up commit, the 7 writer tests pass on macOS (inotify test skipped) and on Linux in a python:3.13-slim container, and the new metadata test fails when the unconditional chmod is restored.

@cwilhit

cwilhit commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@mjudeikis-bot review

@mjudeikis mjudeikis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found.

The change matches the PR description. A no-op refresh no longer calls chmod when the mode is already 0600. Changed contents still go through the atomic mkstemp/fsync/os.replace path. Wrong modes, including setuid, are still repaired.

Checked

  • Read beyond the diff: all of hack/scripts/write-kind-kubeconfig.py and both callers, Makefile:1253 (kind-up-style target) and Makefile:2755 (existing-cluster branch). Also the Makefile test target at line 1239.
  • Correctness: stat.S_IMODE keeps the special bits, so 04600 != 0600 and triggers a chmod. Symlinks are excluded by the existing is_symlink() guard, so path.stat() never follows one. The changed-content path is unchanged, and mkstemp creates the file at 0600. Nothing wrong found.
  • Concurrency: the stat-then-chmod gap is a TOCTOU, but the only effect is an extra repair chmod, which is harmless. Not applicable beyond that.
  • Tenancy/kcp, provider contract, API/codegen, portal: not applicable. This is a dev-only Python script with no Go, API, manifest or portal change.
  • Security: the kubeconfig stays private, and permission repair is preserved and tested for 0644 and 04600. No credentials are logged.
  • Tests: test_unchanged_private_config_emits_no_watch_event would fail on the old code, because chmod to the same mode emits IN_ATTRIB. test_unchanged_content_still_repairs_permissions covers the repair path. Both are Linux-specific, and the inotify test is correctly skipped elsewhere.
  • Ran: python3 -I hack/scripts/write-kind-kubeconfig.test.py gave 6 tests OK. make test-dev-browser gave 20 tests OK.
  • Did not run: Go make build/vet/lint and verify-* targets, because no Go, API, chart or portal file changed. No e2e suite, because the change is dev tooling covered by the unit tests above. The real-Tilt inode/event claim in the PR body was not reproduced here.

@cwilhit
cwilhit force-pushed the codex/preview-kubeconfig-noop branch from 7c9ed7d to 35c816e Compare November 12, 2026 00:33
e2e-infrastructure-up refreshed an existing cluster's kubeconfig with a
shell redirect: not atomic, always a write event, and left at the umask
mode. Use write-kind-kubeconfig.py there too.

The no-event regression test only ran on Linux, while make tilt runs on
macOS. Add a test on every platform that an unchanged refresh keeps the
inode, ctime and mtime. Name the inotify mask bits and report errno when
watch setup fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit
cwilhit marked this pull request as ready for review November 12, 2026 03:30
@cwilhit
cwilhit merged commit d7ca1df into main Nov 12, 2026
41 checks passed
cwilhit added a commit that referenced this pull request Nov 12, 2026
Revert PR #1082 and the first-parent changes from PR #1081, including PR #1083. Preserve the unrelated changes on main through #1056.
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.

2 participants