Skip to content

Use informer lister, context-aware shutdown, and standard logging#50

Merged
jenting merged 1 commit into
mainfrom
refactor/lister-context-logging
Jun 11, 2026
Merged

Use informer lister, context-aware shutdown, and standard logging#50
jenting merged 1 commit into
mainfrom
refactor/lister-context-logging

Conversation

@jenting

@jenting jenting commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

The three deferred code improvements to main.go. Behaviour-preserving except where noted (the lister sort fixes a latent spurious-restart bug).

Informer lister instead of repeated List calls

  • updateConfigMap previously issued a fresh Namespaces().List() API call on every informer event. It now reads from the informer's cached lister — the data is already in memory.
  • Sort the namespace list. The lister iterates a map-backed cache in non-deterministic order; without sorting, the comma-joined value could change between events even when the namespace set is identical, flipping the ConfigMap and triggering an unnecessary main-container restart. Sorting makes the value stable.

Context-aware graceful shutdown

  • Replaced the ad-hoc stopCh + signalCh + os.Exit(0) (which skipped deferred cleanup) with signal.NotifyContext.
  • The context is threaded through the ConfigMap Get/Update/Create calls (no more context.TODO()), so in-flight requests are cancelled on shutdown.
  • A cache-sync failure is now a fatal startup error instead of being silently ignored.

Standard logging

  • Switched fmt.Printf/fmt.Println logging to the standard log package (timestamps), and log.Fatalf for startup failures.

Tests

main_test.go now builds and syncs a namespace lister from the fake clientset (mirroring production) and asserts the sorted ordering. All existing assertions retained, including the nil-map panic regression test.

Verification (local)

  • gofmt -l . → clean
  • go vet ./...
  • make test ✅ (4 tests pass)
  • make build (-race) ✅

🤖 Generated with Claude Code

- Read namespaces from the informer's cached lister instead of issuing a
  fresh List API call on every event, and sort the result so the joined
  ConfigMap value is stable. Non-deterministic cache order could otherwise
  flip the value and trigger spurious container restarts.
- Replace the ad-hoc stop channel and os.Exit(0) with
  signal.NotifyContext, and thread the context through the ConfigMap API
  calls so in-flight requests are cancelled on shutdown.
- Surface a cache-sync failure as a fatal startup error instead of
  silently continuing.
- Switch fmt.Printf/Println logging to the standard log package for
  timestamps, and use log.Fatalf for startup failures.

Tests build and sync a namespace lister from the fake clientset, mirroring
production, and assert the sorted ordering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jenting jenting merged commit 85e158f into main Jun 11, 2026
2 checks passed
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