From 9275adf761f7becb5ab5dfdd33807f2a67e54d2e Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Sat, 29 Aug 2026 12:09:33 +0000 Subject: [PATCH] fix(yurthub): use storage's TableConvertor when implemented Fixes #2781 The multiplexer proxy now checks if the rest.Storage implements rest.TableConvertor and uses it when available. This allows custom storage implementations to provide their own table conversion logic instead of falling back to the default. Signed-off-by: Arunesh Dwivedi --- pkg/yurthub/proxy/multiplexer/multiplexerproxy.go | 15 +++++++++++---- .../proxy/multiplexer/multiplexerproxy_test.go | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/yurthub/proxy/multiplexer/multiplexerproxy.go b/pkg/yurthub/proxy/multiplexer/multiplexerproxy.go index fb3a3c91751..7d7d054e017 100644 --- a/pkg/yurthub/proxy/multiplexer/multiplexerproxy.go +++ b/pkg/yurthub/proxy/multiplexer/multiplexerproxy.go @@ -89,7 +89,7 @@ func (sp *multiplexerProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - reqScope, err := sp.getReqScope(gvr) + reqScope, err := sp.getReqScope(gvr, restStore) if err != nil { util.Err(errors.Wrapf(err, "failed to get req scope"), w, r) return @@ -101,12 +101,20 @@ func (sp *multiplexerProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { handlers.ListResource(lister, watcher, reqScope, forceWatch, minRequestTimeout).ServeHTTP(w, r) } -func (sp *multiplexerProxy) getReqScope(gvr *schema.GroupVersionResource) (*handlers.RequestScope, error) { +func (sp *multiplexerProxy) getReqScope(gvr *schema.GroupVersionResource, restStore rest.Storage) (*handlers.RequestScope, error) { _, fqKindToRegister := sp.restMapperManager.KindFor(*gvr) if fqKindToRegister.Empty() { return nil, fmt.Errorf("gvk is not found for gvr: %v", *gvr) } + // Use storage's custom TableConvertor if available + var tableConvertor rest.TableConvertor + if tc, ok := restStore.(rest.TableConvertor); ok { + tableConvertor = tc + } else { + tableConvertor = rest.NewDefaultTableConvertor(gvr.GroupResource()) + } + return &handlers.RequestScope{ Serializer: scheme.Codecs, ParameterCodec: scheme.ParameterCodec, @@ -118,8 +126,7 @@ func (sp *multiplexerProxy) getReqScope(gvr *schema.GroupVersionResource) (*hand EquivalentResourceMapper: runtime.NewEquivalentResourceRegistry(), - // TODO: Check for the interface on storage - TableConvertor: rest.NewDefaultTableConvertor(gvr.GroupResource()), + TableConvertor: tableConvertor, // TODO: This seems wrong for cross-group subresources. It makes an assumption that a subresource and its parent are in the same group version. Revisit this. Resource: *gvr, diff --git a/pkg/yurthub/proxy/multiplexer/multiplexerproxy_test.go b/pkg/yurthub/proxy/multiplexer/multiplexerproxy_test.go index bd8672868b5..1466ebc9fc2 100644 --- a/pkg/yurthub/proxy/multiplexer/multiplexerproxy_test.go +++ b/pkg/yurthub/proxy/multiplexer/multiplexerproxy_test.go @@ -145,7 +145,7 @@ func TestGetReqScopeReturnsErrorForUnknownGVR(t *testing.T) { sp := &multiplexerProxy{restMapperManager: restMapperManager} unknownGVR := schema.GroupVersionResource{Group: "unknown.example.com", Version: "v1", Resource: "widgets"} - _, err = sp.getReqScope(&unknownGVR) + _, err = sp.getReqScope(&unknownGVR, nil) assert.Error(t, err) }