-
Notifications
You must be signed in to change notification settings - Fork 286
Log MCPRegistry deprecation at most once #6366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChrisJBurns
merged 6 commits into
stacklok:main
from
asjdf:fix/6346-mcpregistry-deprecation-warn-once
Aug 27, 2026
+398
−1
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c65c39
Log MCPRegistry deprecation at most once
asjdf d0914bf
Merge branch 'main' into fix/6346-mcpregistry-deprecation-warn-once
reyortiz3 d6d9347
Fix lint on MCPRegistry warning-handler tests
asjdf 0411047
Place paralleltest nolint on the test function
asjdf 8ea70ab
[fix] keep CRT slog for non-MCPRegistry API warnings
asjdf 927aa43
Merge branch 'main' into fix/6346-mcpregistry-deprecation-warn-once
asjdf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package app | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "k8s.io/client-go/rest" | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
| ) | ||
|
|
||
| // mcpRegistryDeprecationWarningMarker is the unique prefix of the Warning | ||
| // header kube-apiserver sends because the MCPRegistry CRD is marked | ||
| // +kubebuilder:deprecatedversion. The cache LIST/WATCH path surfaces this | ||
| // header even when zero MCPRegistry CRs exist — the repeating trigger is | ||
| // client-go re-establishing the WATCH every 5–10m (reflector timeout), not | ||
| // the 10h default resync (https://github.com/stacklok/toolhive/issues/6346). | ||
| const mcpRegistryDeprecationWarningMarker = "MCPRegistry is deprecated" | ||
|
|
||
| // mcpRegistryOnceWarningHandler logs the MCPRegistry CRD deprecation at most | ||
| // once (first WATCH) and forwards every other API warning to next unchanged. | ||
| // next is the controller-runtime KubeAPIWarningLogger (slog JSON) when | ||
| // constructed with nil. We occupy cfg.WarningHandlerWithContext, so CRT does | ||
| // not auto-install its own handler — other warnings stay on slog because | ||
| // next *is* that CRT logger, not because CRT auto-installs one. | ||
| type mcpRegistryOnceWarningHandler struct { | ||
| once sync.Once | ||
| next rest.WarningHandlerWithContext | ||
| } | ||
|
|
||
| var _ rest.WarningHandlerWithContext = (*mcpRegistryOnceWarningHandler)(nil) | ||
|
|
||
| func newMCPRegistryOnceWarningHandler(next rest.WarningHandlerWithContext) *mcpRegistryOnceWarningHandler { | ||
| if next == nil { | ||
| next = log.NewKubeAPIWarningLogger(log.KubeAPIWarningLoggerOptions{}) | ||
| } | ||
|
ChrisJBurns marked this conversation as resolved.
|
||
| return &mcpRegistryOnceWarningHandler{next: next} | ||
| } | ||
|
|
||
| func (h *mcpRegistryOnceWarningHandler) HandleWarningHeaderWithContext( | ||
| ctx context.Context, code int, agent, text string, | ||
| ) { | ||
| if code == 299 && strings.Contains(text, mcpRegistryDeprecationWarningMarker) { | ||
| h.once.Do(func() { | ||
| h.next.HandleWarningHeaderWithContext(ctx, code, agent, text) | ||
| }) | ||
| return | ||
| } | ||
| h.next.HandleWarningHeaderWithContext(ctx, code, agent, text) | ||
| } | ||
|
|
||
| // installMCPRegistryWarningHandler attaches a once-only handler for the | ||
| // MCPRegistry CRD deprecation so the cache informer cannot spam it on every | ||
| // WATCH re-establishment (client-go re-watches every 5–10m). Other API | ||
| // warnings keep the controller-runtime slog JSON path because next is | ||
| // KubeAPIWarningLogger — not because CRT auto-installs one (we occupy the | ||
| // slot). Pass nil for next in production so the constructor installs that | ||
| // CRT logger; rest.WarningLogger{} would reroute other warnings to klog. | ||
| func installMCPRegistryWarningHandler(cfg *rest.Config, next rest.WarningHandlerWithContext) *mcpRegistryOnceWarningHandler { | ||
| h := newMCPRegistryOnceWarningHandler(next) | ||
| cfg.WarningHandlerWithContext = h | ||
| return h | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.